---
title: |
  | Unemployment, Trust in Government
  | and Satisfaction with Democracy: 
  | An Empirical Investigation*^[ Acknowledgements: I thank the participants of the Swiss Political Science Conference 2016, the annual conference for the European Political Science Association 2015, Hanspeter Kriesi, Stefanie Reher, Jonathan Chapman, Florian Stöckel and anonymous reviewers for their helpful comments. I am also grateful to Giada Gianola for excellent research assistance. Reproduction files and data can be accessed under http://dx.doi.org/10.7910/DVN/DUMGLT. This study has been realized using data collected by the Swiss Household Panel (SHP), which is based at the Swiss Centre of Expertise in the Social Sciences FORS and financed by the Swiss National Science Foundation as well as data from the LISS (Longitudinal Internet Studies for the Social sciences) panel, administered by CentERdata (Tilburg University, The Netherlands). The publication of this article was funded by the "Mannheim Centre for European Social Research". Corresponding Author: mail@paulcbauer.eu, University Mannheim, Mannheim Centre for European Social Research (MZES), 68131  Mannheim Germany, http://www.paulcbauer.eu.]
author: 'Paul C. Bauer'
date: ''
linestretch: 1.2
colorlinks: true
abstract: \noindent\setstretch{1}Evidence suggests that unemployment negatively affects various aspects of individuals' lives. We investigate whether unemployment changes individuals' political evaluations in the form of trust in government and satisfaction with democracy. While most research in this area operates on the macro level, we provide individual-level evidence. In doing so, we investigate the assumed causal link with panel data from Switzerland and the Netherlands. In addition, we study the impact on life satisfaction, a 'control outcome', known to be affected by unemployment. While there is strong evidence that changes in employment status do affect life satisfaction, effects on trust in government and satisfaction with democracy seem mostly absent or negligible in size. \vspace{.8cm}
bibliography: Paperpile.bib
output: 
  bookdown::pdf_document2:
    includes:
      in_header: header.tex
    toc: no
    keep_tex: true
mainfont: Wingdings
sansfont: Wingdings
fontsize: 12pt
documentclass: article
geometry: margin=1in
always_allow_html: yes
header-includes:
   - \usepackage{dcolumn}
   - \usepackage{color}
---

\newcommand*{\secref}[1]{Section~\ref{#1}}

```{r setup, include = FALSE}
  library(knitr)
  set.seed(12345)


# RAW DATA AVAILABLE FROM 
  # Swiss Household Panel: http://forscenter.ch/en/our-surveys/swiss-household-panel/
  # LISS data: http://www.lissdata.nl

# Suggestion: Use the RMarkdown Document Outline in Rstudio to navigate this document.
# Important: As compared to the PDF generated by this .Rmd file, the published manuscript contains various corrections.
  
# SETUP:
  # R version 3.4.1 (2017-06-30) 
  # Platform: x86_64-w64-mingw32/x64 (64-bit) 
  # Running under: Windows 7 x64 (build 7601) Service Pack 1 
  #  
  # Matrix products: default 
  #  
  # locale: 
  # [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252 
  # [4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252     
  #  
  # attached base packages: 
  # [1] stats     graphics  grDevices utils     datasets  methods   base      
  #  
  # other attached packages: 
  # [1] Formula_1.2-1 stargazer_5.2 bindrcpp_0.2  haven_1.0.0   tidyr_0.6.3   stringr_1.2.0 dplyr_0.7.1   plyr_1.8.4    
  # [9] knitr_1.16    
  #  
  # loaded via a namespace (and not attached): 
  #  [1] Rcpp_0.12.14        bdsmatrix_1.3-2     lattice_0.20-35     zoo_1.8-0           assertthat_0.2.0    
  #  [6] rprojroot_1.2       digest_0.6.12       lmtest_0.9-35       R6_2.2.2            backports_1.1.0     
  # [11] acepack_1.4.1       labelled_1.0.0      evaluate_0.10.1     coda_0.19-1         ggplot2_2.2.1       
  # [16] miscTools_0.6-22    rlang_0.1.4         lazyeval_0.2.0      minqa_1.2.4         data.table_1.10.4-3 
  # [21] nloptr_1.0.4        rpart_4.1-11        Matrix_1.2-10       checkmate_1.8.3     rmarkdown_1.6       
  # [26] splines_3.4.1       lme4_1.1-13         readr_1.1.1         foreign_0.8-69      htmlwidgets_0.9     
  # [31] munsell_0.4.3       compiler_3.4.1      pkgconfig_2.0.1     base64enc_0.1-3     maxLik_1.3-4        
  # [36] htmltools_0.3.6     nnet_7.3-12         tibble_1.3.3        gridExtra_2.2.1     htmlTable_1.9       
  # [41] bookdown_0.5        Hmisc_4.0-3         MASS_7.3-47         grid_3.4.1          nlme_3.1-131        
  # [46] arm_1.9-3           gtable_0.2.0        magrittr_1.5        scales_0.5.0        stringi_1.1.5       
  # [51] latticeExtra_0.6-28 sandwich_2.3-4      RColorBrewer_1.1-2  tools_3.4.1         glue_1.1.1          
  # [56] hms_0.3             abind_1.4-5         survival_2.41-3     yaml_2.1.14         colorspace_1.3-2    
  # [61] cluster_2.0.6       bindr_0.1   

  library(plyr)
  library(dplyr)
  library(stringr)
  library(tidyr)
  library(haven)
```





```{r shp-create-data, eval=FALSE, message=FALSE, warning=FALSE, include=FALSE}
# Import and merge data
  shp <- read_dta("shp99_p_user.dta")
  shp <- full_join(shp, read_dta("shp00_p_user.dta"), by="idpers")

  # Identify variables across years by first letters
  relevant.variables <- c("idint", "idpers", "idhous04", "status", "p45", "y02",
                          "l34", "l60", "l61", "l70", "l71", "l80", "l81", "sex",
                          "age", "educat", "wyn", "l101", "l100", "r04","r05",
                          "civsta", "l16", "l01", "n39", "n40", "n41", "n42",
                          "n43", "n44", "n45", "n46", "l21", "i02", "wstat",
                          "p04","p02" ,"reg.1", "w153", "c44", "w12", "w04")

  # Merge and subset variables inbetween (speed!)
  used.vars <- NULL
  for (i in relevant.variables){used.vars <- c(used.vars, names(shp)[grepl(i, names(shp))])}
  shp <- shp[c(used.vars)]
  shp <- full_join(shp, read_dta("shp01_p_user.dta"), by="idpers")
  shp <- full_join(shp, read_dta("shp02_p_user.dta"), by="idpers")
  shp <- full_join(shp, read_dta("shp03_p_user.dta"), by="idpers")
  used.vars <- NULL
  for (i in relevant.variables){used.vars <- c(used.vars, names(shp)[grepl(i, names(shp))])}
  shp <- shp[c(used.vars)]
  shp <- full_join(shp, read_dta("shp04_p_user.dta"), by="idpers")
  shp <- full_join(shp, read_dta("shp05_p_user.dta"), by="idpers")
  shp <- full_join(shp, read_dta("shp06_p_user.dta"), by="idpers")
  shp <- full_join(shp, read_dta("shp07_p_user.dta"), by="idpers")
  used.vars <- NULL
  for (i in relevant.variables){used.vars <- c(used.vars, names(shp)[grepl(i, names(shp))])}
  shp <- shp[c(used.vars)]
  shp <- full_join(shp, read_dta("shp08_p_user.dta"), by="idpers")
  shp <- full_join(shp, read_dta("shp09_p_user.dta"), by="idpers")
  shp <- full_join(shp, read_dta("shp10_p_user.dta"), by="idpers")
  used.vars <- NULL
  for (i in relevant.variables){used.vars <- c(used.vars, names(shp)[grepl(i, names(shp))])}
  shp <- shp[c(used.vars)]
  shp <- full_join(shp, read_dta("shp11_p_user.dta"), by="idpers")
  shp <- full_join(shp, read_dta("shp12_p_user.dta"), by="idpers")
  shp <- full_join(shp, read_dta("shp13_p_user.dta"), by="idpers")
  shp <- full_join(shp, read_dta("shp_lj.dta"), by="idpers")
  used.vars <- NULL
  for (i in relevant.variables){used.vars <- c(used.vars, names(shp)[grepl(i, names(shp))])}
  data <- shp[c(used.vars)]
  rm(shp)

  

  data <- data[ , !duplicated(colnames(data))] # ATTENTION


    
    
#### Unit ID ####
    data <- rename(data, unit = idpers)
    
#### Interview Status #### Type of interviews completed: grid, proxy, personal; 0 = individual questionnaire
    data <- mutate(data, status.1999 = status99,
                         status.2000 = status00,
                         status.2001 = status01,
                         status.2002 = status02,
                         status.2003 = status03,
                         status.2004 = status04,
                         status.2005 = status05,
                         status.2006 = status06,
                         status.2007 = status07,
                         status.2008 = status08,
                         status.2009 = status09,
                         status.2010 = status10,
                         status.2011 = status11,                         
                         status.2012 = status12,
                         status.2013 = status13)
    data <- data %>% labelled::remove_labels() %>%
    mutate_at( .funs = funs(dplyr::recode(., 
                                          `0` = 1,
                                   .default = NA_real_)),
              .vars = vars(matches("status"))
    )
    
    
    
#### OUTCOME VAR ####

  # TRUST IN GOVERNMENT
    data <- mutate(data, trust_in_government.1999 = p99p04,
                         trust_in_government.2000 = p00p04,
                         trust_in_government.2001 = p01p04,
                         trust_in_government.2002 = p02p04,
                         trust_in_government.2003 = p03p04,
                         trust_in_government.2004 = p04p04,
                         trust_in_government.2005 = p05p04,
                         trust_in_government.2006 = p06p04,
                         trust_in_government.2007 = p07p04,
                         trust_in_government.2008 = p08p04,
                         trust_in_government.2009 = p09p04,
                         trust_in_government.2011 = p11p04)# GAP in 2010
    # RECODE
    vars <- names(dplyr::select(data, contains("trust_in_government")))
    for (i in vars){data[c(i)][data[c(i)]==-3 | data[c(i)]==-2 | data[c(i)]==-1] <- NA}
    #table(data$trust_in_government.2011, data$p11p04)
    


    
    
  # SATISFACTION WITH DEMOCRACY
        data <- mutate(data, satisfaction_with_democracy.1999 = p99p02,
                          satisfaction_with_democracy.2000 = p00p02,
                          satisfaction_with_democracy.2001 = p01p02, # GAP BEFORE
                          satisfaction_with_democracy.2002 = p02p02,
                          satisfaction_with_democracy.2003 = p03p02,
                          satisfaction_with_democracy.2004 = p04p02,
                          satisfaction_with_democracy.2005 = p05p02,
                          satisfaction_with_democracy.2006 = p06p02,
                          satisfaction_with_democracy.2007 = p07p02,
                          satisfaction_with_democracy.2008 = p08p02,
                          satisfaction_with_democracy.2009 = p09p02,
                          satisfaction_with_democracy.2011 = p11p02) # GAP IN 2010)#
    # RECODE
    vars <- names(dplyr::select(data, contains("satisfaction_with_democracy"))) 
    for (i in vars){data[c(i)][data[c(i)]==-3 | data[c(i)]==-2 | data[c(i)]==-1] <- NA}
    
    


  # SATISFACTION WITH LIFE
            data <- mutate(data, life_satisfaction.2000 = p00c44, # no 1999
                                 life_satisfaction.2001 = p01c44,
                                 life_satisfaction.2002 = p02c44,
                                 life_satisfaction.2003 = p03c44,
                                 life_satisfaction.2004 = p04c44,
                                 life_satisfaction.2005 = p05c44,
                                 life_satisfaction.2006 = p06c44,
                                 life_satisfaction.2007 = p07c44,
                                 life_satisfaction.2008 = p08c44,
                                 life_satisfaction.2009 = p09c44,
                                 life_satisfaction.2010 = p10c44,
                                 life_satisfaction.2011 = p11c44,
                                 life_satisfaction.2012 = p12c44,
                                 life_satisfaction.2013 = p13c44) # GAP IN 2010)#
    # RECODE
    vars <- names(dplyr::select(data, contains("life_satisfaction"))) 
    for (i in vars){data[c(i)][data[c(i)]==-3 | data[c(i)]==-2 | data[c(i)]==-1] <- NA}
    


#### TREATMENT VAR ####
  # UNEMPLOYMENT at t
    data <- mutate(data, 
                   unemployed.1999 = wstat99,
                   unemployed.2000 = wstat00,
                   unemployed.2001 = wstat01,
                   unemployed.2002 = wstat02,
                   unemployed.2003 = wstat03,
                   unemployed.2004 = wstat04,
                   unemployed.2005 = wstat05,
                   unemployed.2006 = wstat06,
                   unemployed.2007 = wstat07,
                   unemployed.2008 = wstat08,
                   unemployed.2009 = wstat09,
                   unemployed.2010 = wstat10,
                   unemployed.2011 = wstat11,
                   unemployed.2012 = wstat12,
                   unemployed.2013 = wstat13) # GA
    
  
    # RECODE
    data <- data %>% labelled::remove_labels() %>%
    mutate_at( .funs = funs(recode(., # `3` = 0, # not in labor force
                                      `1` = 0, #actively occupied
                                      `2` = 1, #unemployed
                                   .default = NA_real_)),
              .vars = vars(matches("unemployed"))
    )
    #table(data$unemployed.2004, data$wstat04)




  # P04W04: In the last four weeks, have you been looking for a job?
  #  -8 other error; -7 filter error; -3 inapplicable; -2 no answer; -1 does not know; 1 yes; 2 no
        data <- mutate(data, 
                   lookforjob.1999 = p99w04,
                   lookforjob.2000 = p00w04,
                   lookforjob.2001 = p01w04,
                   lookforjob.2002 = p02w04,
                   lookforjob.2003 = p03w04,
                   lookforjob.2004 = p04w04,
                   lookforjob.2005 = p05w04,
                   lookforjob.2006 = p06w04,
                   lookforjob.2007 = p07w04,
                   lookforjob.2008 = p08w04,
                   lookforjob.2009 = p09w04,
                   lookforjob.2010 = p10w04,
                   lookforjob.2011 = p11w04,
                   lookforjob.2012 = p12w04,
                   lookforjob.2013 = p13w04)
    
    
    # RECODE
    library(dplyr)
    data <- data %>% labelled::remove_labels() %>%
    mutate_at( .funs = funs(recode(., `1` = 1, #yes
                                      `2` = 0, #no
                                   .default = NA_real_)),
              .vars = vars(matches("lookforjob"))
    )
    #table(data$lookforjob.1999, data$p99w04)
    #table(data$lookforjob.2005, data$p05w04)    
     
    
# Check whether there are any unemployed people who are not lookign for a job!    
  table(data$lookforjob.1999, data$unemployed.1999)    
  table(data$lookforjob.2001, data$unemployed.2001)   
  table(data$lookforjob.2002, data$unemployed.2002)   
  table(data$lookforjob.2003, data$unemployed.2003)   
  table(data$lookforjob.2004, data$unemployed.2004)   
  table(data$lookforjob.2005, data$unemployed.2005)   
  table(data$lookforjob.2006, data$unemployed.2006)   
  table(data$lookforjob.2007, data$unemployed.2007)   
  table(data$lookforjob.2008, data$unemployed.2008)   
  table(data$lookforjob.2009, data$unemployed.2009)   
  table(data$lookforjob.2010, data$unemployed.2010)   
  table(data$lookforjob.2011, data$unemployed.2011)   
  table(data$lookforjob.2012, data$unemployed.2012)   
  table(data$lookforjob.2013, data$unemployed.2013)   
  # There are people who are not in the labour force but looking for a job (e.g. students, pupils etc.)
  # There are no people that are actively occupied and looking for a job (hence the 0 category)
  
  



#### CONTROL VARs ####
  years <- c("1999","2000","2001","2002", "2003", "2004", "2005", "2006", "2007", "2008" , "2009", "2010", "2011", "2012", "2013")


# AGE
  for (i in years){
    y <- paste("age.", i, sep="")
    z <- paste("age", substr(i, 3, 4), sep="")
    data[c(y)] <- data[z]
    data[c(y)][data[c(y)]<=-1] <- NA
  }
  # table(data$age.2002, data$age02)




# EDUCATION
  for (i in years){
    y <- paste("education.", i, sep="")
    z <- paste("educat", substr(i, 3, 4), sep="")
    data[c(y)] <- data[z]
    data[c(y)][data[c(y)]<=-1] <- NA
  }
  # table(data$education.2007, data$educat07)



# MEMBER: 1 IF MEMBER IN AT LEAST ONE ASSOCIATION (P04N39-P04N46)
  # NO DATA AFTER 2009
  for (i in years[1:11]){
    data[c(paste("member.", i, sep=""))] <- 0
    data[c(paste("member.", i, sep=""))][data[c(paste("p", substr(i, 3, 4), "n39", sep=""))]==1 |
                                         data[c(paste("p", substr(i, 3, 4), "n40", sep=""))]==1 |
                                         data[c(paste("p", substr(i, 3, 4), "n41", sep=""))]==1 |
                                         data[c(paste("p", substr(i, 3, 4), "n42", sep=""))]==1 |
                                         data[c(paste("p", substr(i, 3, 4), "n43", sep=""))]==1 |
                                         data[c(paste("p", substr(i, 3, 4), "n44", sep=""))]==1 |
                                         data[c(paste("p", substr(i, 3, 4), "n45", sep=""))]==1 |
                                         data[c(paste("p", substr(i, 3, 4), "n46", sep=""))]==1] <- 1

  }
  # table(data$member.2007)





# KEEP RELEVANT VARIABLES
  data <- dplyr::select(data, matches('unit|status\\.|trust_in_government|satisfaction_with_democracy|life_satisfaction|unemployed\\.[0-9]{4}|unemployed\\.[0-9]{2}\\.[0-9]{2}|age\\.|education|member'))
    
  
  

  

# CHECK DATA TYPES OF RELEVANT VARIABLES
  str(data)

  
# CREATE LONGFORMAT ####
  data.wide <- dplyr::select(data, matches('unit|trust_in_government|satisfaction_with_democracy|life_satisfaction|unemployed\\.[0-9]{4}|age\\.|education|member'))
  # Convert to long format (row = unit*time*variable)
  data.wide$unit <- factor(data.wide$unit) # convert id variable to factor
  data.long <- data.wide %>% gather(key = key, value = value, -unit)
  data.long <- data.long %>%
  separate(col = key, into = c("variable", "time"), sep = "\\.")
  data.long <-  data.long %>% spread(key = variable, value = value) %>% 
    mutate_all(funs(as.numeric)) %>% arrange(unit, time) 
  data.long <- filter(data.long, age>=18, age<=65)
  nrow(data.long) # check length: length(unique(data.long$time))*length(unique(data$unit))
  # Make it balanced make.pbalanced()
  
  
# NAME DATA OBJECTS  
  data.shp <- data
  data.long.shp <- data.long
  save(data.shp, file = "./data-shp.RData") 
  save(data.long.shp, file = "./data-long-shp.RData")  
  
  rm(list=ls())



  
  
```
  
  
  
  
```{r liss-create-data, eval=FALSE, message=FALSE, warning=FALSE, include=FALSE}

# gender
    data <- read_dta("Gender.dta")
    d08 <- filter(data, wave==200812) %>% 
      mutate(gender.08 = geslacht) %>% dplyr::select(nomem_encr, gender.08)
    d09 <- filter(data, wave==200912) %>% 
      mutate(gender.09 = geslacht) %>% dplyr::select(nomem_encr, gender.09)
    d10 <- filter(data, wave==201012) %>% 
      mutate(gender.10 = geslacht) %>% dplyr::select(nomem_encr, gender.10)
    d11 <- filter(data, wave==201112) %>% 
      mutate(gender.11 = geslacht) %>% dplyr::select(nomem_encr, gender.11)
    d12 <- filter(data, wave==201212) %>% 
      mutate(gender.12 = geslacht) %>% dplyr::select(nomem_encr, gender.12)
    d13 <- filter(data, wave==201312) %>% 
      mutate(gender.13 = geslacht) %>% dplyr::select(nomem_encr, gender.13)
    d14 <- filter(data, wave==201412) %>% 
      mutate(gender.14 = geslacht) %>% dplyr::select(nomem_encr, gender.14)
    
    data <- full_join(d08, d09, by="nomem_encr")
    data <- full_join(data, d10, by="nomem_encr")
    data <- full_join(data, d11, by="nomem_encr")
    data <- full_join(data, d12, by="nomem_encr")
    data <- full_join(data, d13, by="nomem_encr")
    data <- full_join(data, d14, by="nomem_encr")
    rm(d08, d09, d10, d11, d12, d13, d14)
    
    liss <- data
  


  

  
# age  
  data <- read_dta("Age.dta")
  d08 <- filter(data, wave==200812) %>% mutate(age.08 = leeftijd) %>% dplyr::select(nomem_encr, age.08)
  d09 <- filter(data, wave==200912) %>% mutate(age.09 = leeftijd) %>% dplyr::select(nomem_encr, age.09)
  d10 <- filter(data, wave==201012) %>% mutate(age.10 = leeftijd) %>% dplyr::select(nomem_encr, age.10)
  d11 <- filter(data, wave==201112) %>% mutate(age.11 = leeftijd) %>% dplyr::select(nomem_encr, age.11)
  d12 <- filter(data, wave==201212) %>% mutate(age.12 = leeftijd) %>% dplyr::select(nomem_encr, age.12)
  d13 <- filter(data, wave==201312) %>% mutate(age.13 = leeftijd) %>% dplyr::select(nomem_encr, age.13)
  d14 <- filter(data, wave==201412) %>% mutate(age.14 = leeftijd) %>% dplyr::select(nomem_encr, age.14)
  
  data <- full_join(d08, d09, by="nomem_encr")
  data <- full_join(data, d10, by="nomem_encr")
  data <- full_join(data, d11, by="nomem_encr")
  data <- full_join(data, d12, by="nomem_encr")
  data <- full_join(data, d13, by="nomem_encr")
  data <- full_join(data, d14, by="nomem_encr")
  rm(d08, d09, d10, d11, d12, d13, d14)
  
  liss <- full_join(liss, data, by="nomem_encr")
  
  
  
# education
  data <- read_dta("Education.dta")
  d08 <- filter(data, wave==200812) %>% mutate(education.08 = oplmet) %>% dplyr::select(nomem_encr, education.08)
  d09 <- filter(data, wave==200912) %>% mutate(education.09 = oplmet) %>% dplyr::select(nomem_encr, education.09)
  d10 <- filter(data, wave==201012) %>% mutate(education.10 = oplmet) %>% dplyr::select(nomem_encr, education.10)
  d11 <- filter(data, wave==201112) %>% mutate(education.11 = oplmet) %>% dplyr::select(nomem_encr, education.11)
  d12 <- filter(data, wave==201212) %>% mutate(education.12 = oplmet) %>% dplyr::select(nomem_encr, education.12)
  d13 <- filter(data, wave==201312) %>% mutate(education.13 = oplmet) %>% dplyr::select(nomem_encr, education.13)
  d14 <- filter(data, wave==201412) %>% mutate(education.14 = oplmet) %>% dplyr::select(nomem_encr, education.14)
  
  data <- full_join(d08, d09, by="nomem_encr")
  data <- full_join(data, d10, by="nomem_encr")
  data <- full_join(data, d11, by="nomem_encr")
  data <- full_join(data, d12, by="nomem_encr")
  data <- full_join(data, d13, by="nomem_encr")
  data <- full_join(data, d14, by="nomem_encr")
  rm(d08, d09, d10, d11, d12, d13, d14)
  
  liss <- full_join(liss, data, by="nomem_encr")
  
  
# life satisfaction
  data <- read_dta("Life-satisfaction.dta")
  data <- transmute(data, nomem_encr = nomem_encr, 
                 life_satisfaction.08 = cp08a011,
                 life_satisfaction.09 = cp09b011,
                 life_satisfaction.10 = cp10c011,
                 life_satisfaction.11 = cp11d011,
                 life_satisfaction.12 = cp12e011,
                 life_satisfaction.13 = cp13f011,
                 life_satisfaction.14 = cp14g011) 
  liss <- full_join(liss, data, by="nomem_encr")
  
  
# satisfaction with democracy
  data <- read_dta("Satisfaction-with-democracy.dta")
  data <- transmute(data, nomem_encr = nomem_encr, 
                 satisfaction_with_democracy.08 = cv08a044,
                 satisfaction_with_democracy.09 = cv09b044,
                 satisfaction_with_democracy.10 = cv10c044,
                 satisfaction_with_democracy.11 = cv11d044,
                 satisfaction_with_democracy.12 = cv12e044,
                 satisfaction_with_democracy.13 = cv13f044,
                 satisfaction_with_democracy.14 = cv14g044) 
  liss <- full_join(liss, data, by="nomem_encr")
  
  
# trust in government
  data <- read_dta("Trust-in-government.dta")
  data <- transmute(data, nomem_encr = nomem_encr, 
                 trust_in_government.08 = cv08a013,
                 trust_in_government.09 = cv09b013,
                 trust_in_government.10 = cv10c013,
                 trust_in_government.11 = cv11d013,
                 trust_in_government.12 = cv12e013,
                 trust_in_government.13 = cv13f013,
                 trust_in_government.14 = cv14g013) 
  liss <- full_join(liss, data, by="nomem_encr")
  
  
  
# perform paid work
  data <- read_dta("I-perform-paid-work.dta")
  data <- transmute(data, nomem_encr = nomem_encr, 
                 performpaidwork.08 = cw08a088,
                 performpaidwork.09 = cw09b088,
                 performpaidwork.10 = cw10c088,
                 performpaidwork.11 = cw11d088,
                 performpaidwork.12 = cw12e088,
                 performpaidwork.13 = cw13f088,
                 performpaidwork.14 = cw14g088) 
  liss <- full_join(liss, data, by="nomem_encr")
  
  

  
# not working but in past
  data <- read_dta("I-am-looking-for-work-following-the-loss.dta")
  data <- transmute(data, nomem_encr = nomem_encr, 
                 lookingforwork.08 = cw08a091,
                 lookingforwork.09 = cw09b091,
                 lookingforwork.10 = cw10c091,
                 lookingforwork.11 = cw11d091,
                 lookingforwork.12 = cw12e091,
                 lookingforwork.13 = cw13f091,
                 lookingforwork.14 = cw14g091) 
  liss <- full_join(liss, data, by="nomem_encr")
  

# membership
  data <- read_dta("Membership-in-organisations.dta")
  liss <- full_join(liss, data, by="nomem_encr")  

  # Add household identifer! - nohouse_encr
  data <- read_dta("Household-identifier.dta")
  data <- data[!duplicated(data$nomem_encr), ]
  data <- arrange(data, wave)
  liss <- full_join(liss, data, by="nomem_encr") 
  
  data <- liss
  rm(liss)
  


#### OUTCOME VAR ####


    #GENERATE CHANGE/DIFFERENCE IN
    vars <- names(dplyr::select(data, contains("trust_in_government")))
    for (i in vars){data[c(i)][data[c(i)]==999] <- NA}

    #SATISFACTION WITH DEMOCRACY
    vars <- names(dplyr::select(data, contains("satisfaction_with_democracy")))
    for (i in vars){data[c(i)][data[c(i)]==999] <- NA}

    #LIFE SATISFACTION
    vars <- names(dplyr::select(data, contains("life_satisfaction")))
    for (i in vars){data[c(i)][data[c(i)]==999] <- NA}



#### TREATMENT VAR ####


    # Please indicate which of the following statements apply to your situation. Try to be as thorough as you can. Checkmark at least one square; more than one answer is permitted. 
    # cw10c088 I perform paid work (even if is it just for one or several hours per week or for a brief period)
    # cw10c091 I am looking for work following the loss of my previous job
    data$unemployed.08 <- NA
    data$unemployed.09 <- NA
    data$unemployed.10 <- NA
    data$unemployed.11 <- NA
    data$unemployed.12 <- NA
    data$unemployed.13 <- NA
    data$unemployed.14 <- NA
    data$unemployed.08[data$performpaidwork.08==1] <- 0
    data$unemployed.09[data$performpaidwork.09==1] <- 0
    data$unemployed.10[data$performpaidwork.10==1] <- 0
    data$unemployed.11[data$performpaidwork.11==1] <- 0
    data$unemployed.12[data$performpaidwork.12==1] <- 0
    data$unemployed.13[data$performpaidwork.13==1] <- 0
    data$unemployed.14[data$performpaidwork.14==1] <- 0
    data$unemployed.08[data$lookingforwork.08==1] <- 1
    data$unemployed.09[data$lookingforwork.09==1] <- 1
    data$unemployed.10[data$lookingforwork.10==1] <- 1
    data$unemployed.11[data$lookingforwork.11==1] <- 1
    data$unemployed.12[data$lookingforwork.12==1] <- 1
    data$unemployed.13[data$lookingforwork.13==1] <- 1
    data$unemployed.14[data$lookingforwork.14==1] <- 1   
    
    # if sum(cw10c088 through cw10c102)>1 This only lists the labor market options that were marked 'yes' in cw10c088 through
    # cw10c102. cw10c104
    # You gave several answers to the previous question. Please indicate here which of these answers best describes your situation? 
    # Above there might be some inconsistencies
    
    


#### CONTROL VARs ####


  # GENDER -> 1 = Male, 0 = Female
    vars <- names(dplyr::select(data, contains("gender.")))
    for (i in vars){data[c(i)][data[c(i)]==2] <- 0}
    names(data) <- str_replace_all(names(data), "gender", "male")


  # EDUCATION -
    vars <- names(dplyr::select(data, contains("education.")))
    for (i in vars){
    data[c(i)][data[c(i)]==7] <- NA
    data[c(i)][data[c(i)]==8] <- 0
    data[c(i)][data[c(i)]==9] <- 0
      }




    #MEMBER IN AT LEAST ONE ASSOCIATION -> 1=Yes, 0=No
    data$member.08 <- 0
    data$member.08[data$cs08a006==1 | data$cs08a011==1 | data$cs08a016==1 |
                      data$cs08a021==1 | data$cs08a026==1 | #data$cs08a031==1 |
                          data$cs08a036==1 | data$cs08a041 ==1| data$cs08a046==1 |
                      data$cs08a051==1 | data$cs08a056==1 | data$cs08a061==1] <- 1
    data$member.09 <- 0
    data$member.09[data$cs09b006==1 | data$cs09b011==1 | data$cs09b016==1 |
                      data$cs09b021==1 | data$cs09b026==1 | #data$cs09b031==1 |
                        data$cs09b036==1 | data$cs09b041 ==1| data$cs09b046==1 |
                      data$cs09b051==1 | data$cs09b056==1 | data$cs09b061==1] <- 1
    data$member.10 <- 0
    data$member.10[data$cs10c006==1 | data$cs10c011==1 | data$cs10c016==1 |
                      data$cs10c021==1 | data$cs10c026==1 | #data$cs10c031==1 |
                          data$cs10c036==1 | data$cs10c041 ==1| data$cs10c046==1 |
                      data$cs10c051==1 | data$cs10c056==1 | data$cs10c061==1] <- 1
    data$member.11 <- 0
    data$member.11[data$cs11d006==1 | data$cs11d011==1 | data$cs11d016==1 |
                      data$cs11d021==1 | data$cs11d026==1 | #data$cs11d031==1 |
                          data$cs11d036==1 | data$cs11d041 ==1| data$cs11d046==1 |
                      data$cs11d051==1 | data$cs11d056==1 | data$cs11d061==1] <- 1
    data$member.12 <- 0
    data$member.12[data$cs12e006==1 | data$cs12e011==1 | data$cs12e016==1 |
                      data$cs12e021==1 | data$cs12e026==1 | #data$cs12e031==1 |
                          data$cs12e036==1 | data$cs12e041 ==1| data$cs12e046==1 |
                      data$cs12e051==1 | data$cs12e056==1 | data$cs12e061==1] <- 1
    data$member.13 <- 0
    data$member.13[data$cs13f006==1 | data$cs13f011==1 | data$cs13f016==1 |
                      data$cs13f021==1 | data$cs13f026==1 | #data$cs13f031==1 |
                          data$cs13f036==1 | data$cs13f041 ==1| data$cs13f046==1 |
                      data$cs13f051==1 | data$cs13f056==1 | data$cs13f061==1] <- 1
    data$member.14 <- 0
    data$member.14[data$cs14g006==1 | data$cs14g011==1 | data$cs14g016==1 |
                      data$cs14g021==1 | data$cs14g026==1 | #data$cs14g031==1 |
                          data$cs14g036==1 | data$cs14g041 ==1| data$cs14g046==1 |
                      data$cs14g051==1 | data$cs14g056==1 | data$cs14g061==1] <- 1
    names(data) <- gsub("(\\.)([0-9][0-9])", "\\120\\2", names(data))
   

    
    
    # rename variables
    data <- rename(data, unit = nomem_encr)
    

    # keep relevant variables
    data <- dplyr::select(data, 
                          matches('unit|male|age|trust_in_government|satisfaction_with_democracy|life_satisfaction|unemployed|education|member'))
    
  
    # check object types
      str(data)
    
    

    # replace NaN with NA
      data[is.na(data)] <- NA
      
      
    # CREATE LONGFORMAT ####
      data.wide <- data
      # Convert to long format (row = unit*time*variable)
      # data.wide$unit <- factor(data.wide$unit) # convert id variable to factor
      data.long <- data.wide %>% gather(key = key, value = value, -unit)
      data.long <- data.long %>%
      separate(col = key, into = c("variable", "time"), sep = "\\.")
      data.long <-  data.long %>% spread(key = variable, value = value) %>% 
        mutate_all(funs(as.numeric)) %>% arrange(unit, time) 
      data.long <- filter(data.long, age>=18, age<=65) %>% dplyr::select(-male)
      nrow(data.long) # CHECK: length(unique(data.long$time))*length(unique(data$unit))

      
      
    # name data objects
      data.liss <- data
      data.long.liss <- data.long
      # data.wide.liss <- data.wide

      
      save(data.liss, file = "./data-liss.RData") 
      save(data.long.liss, file = "./data-long-liss.RData")  

      rm(list=ls())

      
      
```      
    
     
     
      
```{r table-1, message=FALSE, warning=FALSE, include=FALSE}   

#### START: REPRODUCTION W/O RAW DATA HERE ####

      
      load(file = "./data-long-shp.RData") 
      load(file = "./data-long-liss.RData") 
      x1 <- group_by(data.long.shp, time) %>% summarise_all(funs(sum(.==0, na.rm = TRUE))) %>% pull(unemployed)
      x2 <- group_by(data.long.shp, time) %>% summarise_all(funs(sum(.==1, na.rm = TRUE))) %>% pull(unemployed)
      names(x1) <- 1999:2013
      names(x2) <- 1999:2013
      
      x3 <- group_by(data.long.liss, time) %>% summarise_all(funs(sum(.==0, na.rm = TRUE))) %>% pull(unemployed)
      x4 <- group_by(data.long.liss, time) %>% summarise_all(funs(sum(.==1, na.rm = TRUE))) %>% pull(unemployed)
      names(x3) <- 2008:2014
      names(x4) <- 2008:2014
      samples <- data.frame(bind_rows(x1,x2,x3,x4))
      row.names(samples) <- c("SHP: Employed", "SHP: Unemployed", "LISS: Employed", "LISS: Unemployed")
      names(samples) <- 1999:2014
      stargazer::stargazer(samples, summary = FALSE, 
                out = "table-1.tex",
                font.size = "tiny",
                label = "table-1",
                table.placement="!ht",
                column.sep.width = ".1pt", 
                title = "Unemployment across years",
                digit.separator="")

      rm(list=ls())      
      
      
```

  
  
```{r shp-analyze-data, message=FALSE, warning=FALSE, include=FALSE}
  library(dplyr)
  library(stargazer)

  
  load(file = "./data-long-shp.RData")  
  data.long <- data.long.shp
  rm(data.long.shp)
  
  
# Table 6 & 7: SUMMARY STATISTICS ####
  summary.stats <- 
  bind_cols(
  data.long %>% dplyr::select(-unit) %>%
    group_by(time) %>%
    summarise_all(funs(sum(!is.na(.))))  %>%
    gather(key = "variable", 
           value = "n",
           -time),
  
  data.long %>% dplyr::select(-unit) %>%
    group_by(time) %>%
    summarise_all(funs(mean(., na.rm = TRUE)))  %>%
    gather(key = "variable2", 
           value = "mean",
           -time),
  
   data.long %>% dplyr::select(-unit) %>%
    group_by(time) %>%
    summarise_all(funs(sd(., na.rm = TRUE)))  %>%
    gather(key = "variable3", 
           value = "sd",
           -time),
  
    data.long %>% dplyr::select(-unit) %>%
    group_by(time) %>%
   summarise_all(funs(min(., na.rm = TRUE)))  %>%
    gather(key = "variable4", 
           value = "min",
           -time),  
  
    data.long %>% dplyr::select(-unit) %>%
    group_by(time) %>%
   summarise_all(funs(max(., na.rm = TRUE)))  %>%
    gather(key = "variable5", 
           value = "max",
           -time))  %>% dplyr::select(-variable2, -variable3, -variable4, -variable5,
                               -time2, -time3, -time4) %>%
    filter(n!=0) %>% unite(variable, time, col = "variable")
  
    summary.stats[,4:5] <- round(summary.stats[,4:5],2)
  
    summary.stats$variable <- Hmisc::capitalize(str_replace_all(summary.stats$variable, "_|\\.", " "))  
    names(summary.stats) <- c("Variable", "N", "Time", "Mean", "SD", "Min", "Max")
  stargazer(summary.stats[1:55,], summary = FALSE, out="./table-6.tex", type="latex", 
              label = "table-6", font.size="scriptsize", table.placement="!ht", column.sep.width = ".2pt" , title = "SHP Switzerland: summary statistics", digits = 2,
                rownames = FALSE)
  
    stargazer(summary.stats[56:94,], summary = FALSE, out="./table-7.tex", type="latex", 
              label = "table-7", font.size="scriptsize", table.placement="!ht", column.sep.width = ".2pt" , title = "SHP Switzerland: summary statistics continued", digits = 2,
                rownames = FALSE)

    rm(summary.stats)
    

      library(plm)
    
# M1-M6: POOLING ####
    
      fit.pooling.trust_in_government <- plm(trust_in_government ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.trust_in_government)
      
      fit.pooling.satisfaction_with_democracy <- plm(satisfaction_with_democracy ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.satisfaction_with_democracy)
      
      fit.pooling.life_satisfaction <- plm(life_satisfaction ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.life_satisfaction)
    
    
      fit.pooling.control.trust_in_government <- plm(trust_in_government ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.control.trust_in_government)
      
      fit.pooling.control.satisfaction_with_democracy <- plm(satisfaction_with_democracy ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.control.satisfaction_with_democracy)
      
      fit.pooling.control.life_satisfaction <- plm(life_satisfaction ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.control.life_satisfaction)
      



# M13-M18: FIXED EFFECTS/WITHIN ####
    
      fit.fe.trust_in_government <- plm(trust_in_government ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.trust_in_government)
      
      fit.fe.satisfaction_with_democracy <- plm(satisfaction_with_democracy ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.satisfaction_with_democracy)
      
      fit.fe.life_satisfaction <- plm(life_satisfaction ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.life_satisfaction)
    
    
      fit.fe.control.trust_in_government <- plm(trust_in_government ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.control.trust_in_government)
      
      fit.fe.control.satisfaction_with_democracy <- plm(satisfaction_with_democracy ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.control.satisfaction_with_democracy)
      
      fit.fe.control.life_satisfaction <- plm(life_satisfaction ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.control.life_satisfaction)
      
      

  detach("package:plm", unload=TRUE)
  
  
  
  

  
  library(wfe)

  
# M25-M30: WEIGHTED LINEAR: FIXED EFFECTS ####


#### trust_in_government ###
  fit.wfe_fe.trust_in_government <- wfe(trust_in_government ~ unemployed, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.trust_in_government)

  fit.wfe_fe.control.trust_in_government <- wfe(trust_in_government ~ unemployed + age + education  + member, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.control.trust_in_government)
  

#### satisfaction_with_democracy ###
  fit.wfe_fe.satisfaction_with_democracy <- wfe(satisfaction_with_democracy ~ unemployed, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.satisfaction_with_democracy)

  fit.wfe_fe.control.satisfaction_with_democracy <- wfe(satisfaction_with_democracy ~ unemployed + age + education  + member, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.control.satisfaction_with_democracy)


#### life_satisfaction ###
  fit.wfe_fe.life_satisfaction <- wfe(life_satisfaction ~ unemployed, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.life_satisfaction)

  
  fit.wfe_fe.control.life_satisfaction <- wfe(life_satisfaction ~ unemployed + age + education  + member, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.control.life_satisfaction)


  rm(data.long)    
  
  
  

  
  
# SHP: GENERATE MODEL OBJECTS ####  
      objects <- c("fit.pooling.trust_in_government", "fit.pooling.control.trust_in_government", 
                   "fit.pooling.satisfaction_with_democracy", "fit.pooling.control.satisfaction_with_democracy",
                   "fit.pooling.life_satisfaction", "fit.pooling.control.life_satisfaction", "fit.fe.trust_in_government",
                   "fit.fe.control.trust_in_government", "fit.fe.satisfaction_with_democracy",
                   "fit.fe.control.satisfaction_with_democracy", "fit.fe.life_satisfaction", "fit.fe.control.life_satisfaction",
                   "fit.wfe_fe.trust_in_government", "fit.wfe_fe.control.trust_in_government", "fit.wfe_fe.satisfaction_with_democracy",
                   "fit.wfe_fe.control.satisfaction_with_democracy", "fit.wfe_fe.life_satisfaction",
                   "fit.wfe_fe.control.life_satisfaction") 
      for(i in objects){assign(paste0("shp.", i), get(i))} # store objects with new name
      rm(list = objects)
      rm(i, objects) # rm(i, names, objects, x, z)
    
      
      
      
      
#### SHP: DATA FOR PLOT ####
  names <- c("shp.fit.pooling.trust_in_government", "shp.fit.pooling.control.trust_in_government", "shp.fit.pooling.satisfaction_with_democracy", "shp.fit.pooling.control.satisfaction_with_democracy", "shp.fit.pooling.life_satisfaction", "shp.fit.pooling.control.life_satisfaction", "shp.fit.fe.trust_in_government", "shp.fit.fe.control.trust_in_government", "shp.fit.fe.satisfaction_with_democracy", "shp.fit.fe.control.satisfaction_with_democracy", "shp.fit.fe.life_satisfaction", "shp.fit.fe.control.life_satisfaction", "shp.fit.wfe_fe.trust_in_government", "shp.fit.wfe_fe.control.trust_in_government", "shp.fit.wfe_fe.satisfaction_with_democracy", "shp.fit.wfe_fe.control.satisfaction_with_democracy", "shp.fit.wfe_fe.life_satisfaction", "shp.fit.wfe_fe.control.life_satisfaction")
  plot.data.shp <- data.frame(coef = rep(NA, 18), se =  rep(NA, 18), t =  rep(NA, 18), p =  rep(NA, 18))
  row.names(plot.data.shp) <- names
  i <- 1
  for(z in list(shp.fit.pooling.trust_in_government, shp.fit.pooling.control.trust_in_government, shp.fit.pooling.satisfaction_with_democracy, shp.fit.pooling.control.satisfaction_with_democracy, shp.fit.pooling.life_satisfaction, shp.fit.pooling.control.life_satisfaction, shp.fit.fe.trust_in_government,  shp.fit.fe.control.trust_in_government, shp.fit.fe.satisfaction_with_democracy, shp.fit.fe.control.satisfaction_with_democracy, shp.fit.fe.life_satisfaction, shp.fit.fe.control.life_satisfaction, shp.fit.wfe_fe.trust_in_government, shp.fit.wfe_fe.control.trust_in_government, shp.fit.wfe_fe.satisfaction_with_democracy, shp.fit.wfe_fe.control.satisfaction_with_democracy, shp.fit.wfe_fe.life_satisfaction, shp.fit.wfe_fe.control.life_satisfaction)){
    # print(coef(summary(fit))[1,1])
    
    # print(deparse(substitute(z)))
    x <- coef(summary(z))["unemployed",]
    plot.data.shp[i,"coef"] <- x[1]
    plot.data.shp[i,"se"] <- x[2]
    plot.data.shp[i,"t"] <- x[3]
    plot.data.shp[i,"p"] <- x[4]
    i <- i + 1
  }


  
  
  
```








```{r liss-analyze-data, message=FALSE, warning=FALSE, include=FALSE}
  load(file = "./data-long-liss.RData")  
  data.long <- data.long.liss
  rm(data.long.liss)
  
# Table 8: SUMMARY STATISTICS ####
  summary.stats <- 
  bind_cols(
  data.long %>% dplyr::select(-unit) %>%
    group_by(time) %>%
    summarise_all(funs(sum(!is.na(.))))  %>%
    gather(key = "variable", 
           value = "n",
           -time),
  
  data.long %>% dplyr::select(-unit) %>%
    group_by(time) %>%
    summarise_all(funs(mean(., na.rm = TRUE)))  %>%
    gather(key = "variable2", 
           value = "mean",
           -time),
  
   data.long %>% dplyr::select(-unit) %>%
    group_by(time) %>%
    summarise_all(funs(sd(., na.rm = TRUE)))  %>%
    gather(key = "variable3", 
           value = "sd",
           -time),
  
    data.long %>% dplyr::select(-unit) %>%
    group_by(time) %>%
   summarise_all(funs(min(., na.rm = TRUE)))  %>%
    gather(key = "variable4", 
           value = "min",
           -time),  
  
    data.long %>% dplyr::select(-unit) %>%
    group_by(time) %>%
   summarise_all(funs(max(., na.rm = TRUE)))  %>%
    gather(key = "variable5", 
           value = "max",
           -time))  %>% dplyr::select(-variable2, -variable3, -variable4, -variable5,
                               -time2, -time3, -time4) %>%
    filter(n!=0) %>% unite(variable, time, col = "variable")
  
  
    
    summary.stats[,4:5] <- round(summary.stats[,4:5],2)
  
    summary.stats$variable <- Hmisc::capitalize(str_replace_all(summary.stats$variable, "_|\\.", " "))  
    names(summary.stats) <- c("Variable", "N", "Time", "Mean", "SD", "Min", "Max")  
    stargazer::stargazer(summary.stats, summary = FALSE, out="./table-8.tex", type="latex",
                label = "table-8", font.size="scriptsize", table.placement="!ht",
                column.sep.width = ".2pt", title = "LISS Netherlands: summary statistics", digits = 2,
                rownames = FALSE)
    rm(summary.stats)

  
      library(plm)
    
# M7-M12: POOLING ####
    
      fit.pooling.trust_in_government <- plm(trust_in_government ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.trust_in_government)
      
      fit.pooling.satisfaction_with_democracy <- plm(satisfaction_with_democracy ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.satisfaction_with_democracy)
      
      fit.pooling.life_satisfaction <- plm(life_satisfaction ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.life_satisfaction)
    
    
      fit.pooling.control.trust_in_government <- plm(trust_in_government ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.control.trust_in_government)
      
      fit.pooling.control.satisfaction_with_democracy <- plm(satisfaction_with_democracy ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.control.satisfaction_with_democracy)
      
      fit.pooling.control.life_satisfaction <- plm(life_satisfaction ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "pooling")
      summary(fit.pooling.control.life_satisfaction)
      
      
    
      
      
      
# M19-M24: FIXED EFFECTS/WITHIN ####
    
      fit.fe.trust_in_government <- plm(trust_in_government ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.trust_in_government)
      
      fit.fe.satisfaction_with_democracy <- plm(satisfaction_with_democracy ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.satisfaction_with_democracy)
      
      fit.fe.life_satisfaction <- plm(life_satisfaction ~ unemployed, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.life_satisfaction)
    
    
      fit.fe.control.trust_in_government <- plm(trust_in_government ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.control.trust_in_government)
      
      fit.fe.control.satisfaction_with_democracy <- plm(satisfaction_with_democracy ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.control.satisfaction_with_democracy)
      
      fit.fe.control.life_satisfaction <- plm(life_satisfaction ~ unemployed+ age + education  + member, 
                        data = data.long,
                        index = c("unit", "time"),
                        model = "within")
      summary(fit.fe.control.life_satisfaction)

      detach("package:plm", unload=TRUE)
  
  
  
  

  library(wfe)  
  
# M31-M36: WEIGHTED LINEAR: FIXED EFFECTS ####


#### trust_in_government ###
  fit.wfe_fe.trust_in_government <- wfe(trust_in_government ~ unemployed, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.trust_in_government)

  fit.wfe_fe.control.trust_in_government <- wfe(trust_in_government ~ unemployed + age + education  + member, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.control.trust_in_government)
  

#### satisfaction_with_democracy ###
  fit.wfe_fe.satisfaction_with_democracy <- wfe(satisfaction_with_democracy ~ unemployed, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.satisfaction_with_democracy)

  fit.wfe_fe.control.satisfaction_with_democracy <- wfe(satisfaction_with_democracy ~ unemployed + age + education  + member, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.control.satisfaction_with_democracy)


#### life_satisfaction ###
  fit.wfe_fe.life_satisfaction <- wfe(life_satisfaction ~ unemployed, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.life_satisfaction)

  
  fit.wfe_fe.control.life_satisfaction <- wfe(life_satisfaction ~ unemployed + age + education  + member, data = data.long, treat = "unemployed",
               unit.index = "unit", time.index = "time", method = "unit",
               qoi = "ate", estimator =NULL, hetero.se=TRUE, auto.se=TRUE,
               White = TRUE, White.alpha = 0.05, verbose = TRUE)
  summary(fit.wfe_fe.control.life_satisfaction)

  
 
  detach("package:wfe", unload=TRUE)
      
  rm(data.long)   
  
  
 
# LISS: GENERATE MODEL OBJECTS ####
      objects <- c("fit.pooling.trust_in_government", "fit.pooling.control.trust_in_government", 
                   "fit.pooling.satisfaction_with_democracy", "fit.pooling.control.satisfaction_with_democracy",
                   "fit.pooling.life_satisfaction", "fit.pooling.control.life_satisfaction", 
                   "fit.fe.trust_in_government", "fit.fe.control.trust_in_government", "fit.fe.satisfaction_with_democracy",
                   "fit.fe.control.satisfaction_with_democracy", "fit.fe.life_satisfaction", 
                   "fit.fe.control.life_satisfaction", "fit.wfe_fe.trust_in_government", 
                   "fit.wfe_fe.control.trust_in_government", "fit.wfe_fe.satisfaction_with_democracy",
                   "fit.wfe_fe.control.satisfaction_with_democracy", "fit.wfe_fe.life_satisfaction", "fit.wfe_fe.control.life_satisfaction") 
      for(i in objects){assign(paste0("liss.", i), get(i))} 
      rm(list = objects)
      rm(i, names, objects, x, z)
  
  
#### LISS: DATA FOR PLOT ####
  names <- c("liss.fit.pooling.trust_in_government", "liss.fit.pooling.control.trust_in_government", "liss.fit.pooling.satisfaction_with_democracy", "liss.fit.pooling.control.satisfaction_with_democracy", "liss.fit.pooling.life_satisfaction", "liss.fit.pooling.control.life_satisfaction", "liss.fit.fe.trust_in_government", 
             "liss.fit.fe.control.trust_in_government", "liss.fit.fe.satisfaction_with_democracy", "liss.fit.fe.control.satisfaction_with_democracy", "liss.fit.fe.life_satisfaction", "liss.fit.fe.control.life_satisfaction", "liss.fit.wfe_fe.trust_in_government", "liss.fit.wfe_fe.control.trust_in_government", "liss.fit.wfe_fe.satisfaction_with_democracy", "liss.fit.wfe_fe.control.satisfaction_with_democracy", "liss.fit.wfe_fe.life_satisfaction", "liss.fit.wfe_fe.control.life_satisfaction")
  plot.data.liss <- data.frame(coef = rep(NA, 18), se =  rep(NA, 18), t =  rep(NA, 18), p =  rep(NA, 18))
  row.names(plot.data.liss) <- names
  i <- 1
  for(z in list(liss.fit.pooling.trust_in_government, liss.fit.pooling.control.trust_in_government, 
                liss.fit.pooling.satisfaction_with_democracy, liss.fit.pooling.control.satisfaction_with_democracy, 
                liss.fit.pooling.life_satisfaction, liss.fit.pooling.control.life_satisfaction, liss.fit.fe.trust_in_government,
                liss.fit.fe.control.trust_in_government, liss.fit.fe.satisfaction_with_democracy, 
                liss.fit.fe.control.satisfaction_with_democracy, liss.fit.fe.life_satisfaction, liss.fit.fe.control.life_satisfaction,
                liss.fit.wfe_fe.trust_in_government, liss.fit.wfe_fe.control.trust_in_government, 
                liss.fit.wfe_fe.satisfaction_with_democracy, liss.fit.wfe_fe.control.satisfaction_with_democracy, 
                liss.fit.wfe_fe.life_satisfaction, liss.fit.wfe_fe.control.life_satisfaction)){
    # print(coef(summary(fit))[1,1])
    
    # print(deparse(substitute(z)))
    x <- coef(summary(z))["unemployed",]
    plot.data.liss[i,"coef"] <- x[1]
    plot.data.liss[i,"se"] <- x[2]
    plot.data.liss[i,"t"] <- x[3]
    plot.data.liss[i,"p"] <- x[4]
    i <- i + 1
  }


  
#### MERGE PLOT DATA ####  
    plot.data <- rbind(plot.data.shp, plot.data.liss)
    plot.data$upper95 <- plot.data$coef + 1.96*plot.data$se
    plot.data$lower95 <- plot.data$coef - 1.96*plot.data$se  
    plot.data$outcome <- str_replace(str_extract_all(rownames(plot.data), "\\.[a-z_]*$"), "\\.", "")
    plot.data$survey <- str_replace(str_extract(rownames(plot.data), "[a-z_]*\\."), "\\.", "")
    plot.data$pch[plot.data$survey=="shp"] <- 20
    plot.data$pch[plot.data$survey=="liss"] <- 18
    plot.data$model <- gsub("\\.[a-z_]*$", "", gsub("^[a-z]*\\.[a-z]*\\.", "", rownames(plot.data)))
    
    plot.data$x.modeltype <- as.numeric(mapvalues(plot.data$model,
                                       from = c("pooling", "pooling.control", "fe", "fe.control", "wfe_fe", "wfe_fe.control" ),
                                       to = c(1,1,2,2,3,3)))
    plot.data$x.controltype <- as.numeric(mapvalues(plot.data$model,
                                       from = c("pooling", "pooling.control", "fe", "fe.control", "wfe_fe", "wfe_fe.control" ),
                                       to = c(1,2,1,2,1,2)))
    plot.data$x.datatype <- as.numeric(mapvalues(plot.data$survey,
                                       from = c("shp", "liss" ),
                                       to = c(1,2)))
    plot.data$x.outcometype <- as.numeric(mapvalues(plot.data$outcome,
                                       from = c("trust_in_government", "satisfaction_with_democracy", "life_satisfaction"),
                                       to = c(1,2,3)))
    # Add Model Names
      plot.data <- arrange(plot.data, x.modeltype, x.datatype, x.outcometype, x.controltype)
      plot.data$name <- paste("M", 1:36, sep="")
    
    # Rearrange for plot and add x coordinates
      plot.data <- arrange(plot.data, x.modeltype, x.controltype, x.outcometype, x.datatype)
      plot.data$x.plotorder <- 1:36
      
    # Add x-axis positions
      positions <- c(0.2, 0.3, 0.5, 0.6, 0.8, 0.9) 
      plot.data$x.positions <- rep(positions, 6) + rep(0:5, each = 6)
    # Add colours
      plot.data$color <- mapvalues(plot.data$outcome,
                                       from = c("trust_in_government", "satisfaction_with_democracy", "life_satisfaction"),
                                       to = c("black","orange","blue"))
    # Add symbols
      plot.data$symbol <- as.numeric(mapvalues(plot.data$survey,
                                       from = c("shp", "liss" ),
                                       to = c(20,18)))
    # Add symbols readable for black & white
      plot.data$symbol2[plot.data$survey=="shp" & plot.data$outcome=="trust_in_government"] <- 16
      plot.data$symbol2[plot.data$survey=="shp" & plot.data$outcome=="satisfaction_with_democracy"] <- 15        
      plot.data$symbol2[plot.data$survey=="shp" & plot.data$outcome=="life_satisfaction"] <- 17 
      plot.data$symbol2[plot.data$survey=="liss" & plot.data$outcome=="trust_in_government"] <- 1
      plot.data$symbol2[plot.data$survey=="liss" & plot.data$outcome=="satisfaction_with_democracy"] <- 0        
      plot.data$symbol2[plot.data$survey=="liss" & plot.data$outcome=="life_satisfaction"] <- 2
    # Add symbols readable for black & white
      
      rm(plot.data.liss, plot.data.shp, i, x, z, names, positions)
      
      
# FIGURE 1: Visualization of effects across models, outcomes and datasets ####
jpeg("fig-1.jpg", width = 8, height = 4, units = 'in', res = 800)
par(oma = c(0,0,0,0), mar = c(2,4,1,2))




plot(1, type="n", 
     xlab="", 
     ylab="Outcome", 
     ylim = c(-1.1,1.1),
     xlim = c(0.2,5.8),
     xaxt='n',
    cex.axis= 0.8)




abline(h = 0, col = "red", lty = 2)
abline(h = c(-1, -0.75, -0.5, -0.25, 0.25, 0.5, 0.75, 1), col = "lightgray")
abline(v = c(1, 2, 3, 4, 5, lty = 2), col = "black", lty = 3)
points(plot.data$x.positions, 
     plot.data$coef, 
     pch = plot.data$symbol2,
     col = plot.data$color) 
segments(x0 = plot.data$x.positions,
      y0 = plot.data$lower95,
      x1 = plot.data$x.positions,
      y1 = plot.data$upper95,
      col = plot.data$color)

# Plot Modelnames
  text(plot.data$x.positions,
       plot.data$upper95 + 0.05, 
       plot.data$name,
       srt = 90,
       cex = 0.7,
       adj = c(0,NA))
     


axis(1, at=0.5:5.5, labels=c("Pooled", "Pooled w.\nControls",
                         "FE", "FE w.\nControls",
                         "WFE", "WFE w.\nControls"), las=1, tck=-0.01, cex.axis= 0.8)



pos <- legend('topright', 
              legend=c("Trust in government",
                       "Satisfaction w. democracy",
                       "Life satisfaction"),
              # box.lwd = 0,
              #box.col = "#FFFFFF80",
              bg = "#FFFFFF80",
              bty = "n",
              cex = 0.8)
points(x = rep(pos$text$x, times=2) - c(0.25,0.1),
       y = rep(pos$text$y, each=2),
       pch = c(16,1,15,0,17,2),
       col = rep(c("black", "orange", "blue"), each=2))

text(x = pos$text$x[1]- c(0.25,0.1),
     y = rep(pos$text$y[3],2)-0.17,
     labels = c("SHP", "LISS"),
     srt = 90,
     cex = 0.8)

dev.off()



    
  


      
      
      dep.var.labels <- Hmisc::capitalize(str_replace_all(c("trust_in_government", "satisfaction_with_democracy", "life_satisfaction", "trust_in_government", "satisfaction_with_democracy", "life_satisfaction"), "_", " "))
      
   
      
      
      
      
# TABLE 3: POOLING TABLE ####
        stargazer(shp.fit.pooling.trust_in_government,  shp.fit.pooling.control.trust_in_government, 
                shp.fit.pooling.satisfaction_with_democracy, shp.fit.pooling.control.satisfaction_with_democracy,
                shp.fit.pooling.life_satisfaction, shp.fit.pooling.control.life_satisfaction,
                
                liss.fit.pooling.trust_in_government,  liss.fit.pooling.control.trust_in_government, 
                liss.fit.pooling.satisfaction_with_democracy, liss.fit.pooling.control.satisfaction_with_democracy,
                liss.fit.pooling.life_satisfaction, liss.fit.pooling.control.life_satisfaction,
                type = "latex",
                out="./table-3.tex",
                omit.stat=c("LL","ser","f","adj.rsq"), 
                ci=FALSE, digits=2, 
                ci.level=0.95,
                single.row=FALSE, 
                label = "table-3", 
                font.size="scriptsize", 
                table.placement="!ht", 
                column.sep.width = "-4pt",
                title = "SHP Switzerland and LISS Netherlands: pooling",
                align = TRUE,
                column.labels = c("(M1)", "(M2)", "(M3)", "(M4)", "(M5)", "(M6)", "(M7)", "(M8)", "(M9)", "(M10)", "(M11)", "(M12)"), 
                model.names = FALSE,
                model.numbers = FALSE,
                star.cutoffs = c(0.05, 0.01, 0.001),
                                covariate.labels = c("Unemployed", "Age", "Education", "Member"),
                dep.var.labels = dep.var.labels) 
      
    
           
        # CUSTOM TABLE
                custom_table <- function(dataset_labels, ..., cat_output=TRUE, out_file=NULL) {
                    tbl <- capture.output(stargazer::stargazer(...))
                    pattern1 <- 'Dependent variable:'
                    pattern2 <- '(?<= \\& ).+(?= \\\\)'
                    first_row_index <- which(grepl(pattern=pattern1, x=tbl))
                    first_row <- tbl[first_row_index]
                    colspan <- as.numeric(gsub(pattern='[^0-9]+', replacement='', first_row))
                    colspan <- colspan / length(dataset_labels)
                    new_first_row <- sub('[0-9]+', colspan, first_row)
                    replacement <- rep(stringr::str_extract(new_first_row, pattern2), 2)
                    replacement <- stringr::str_replace(replacement, pattern1, dataset_labels)
                    replacement <- paste(replacement, collapse=' & ')
                    new_first_row <- stringr::str_replace(new_first_row, pattern2, replacement)
                    new_first_row <- stringr::str_replace_all(new_first_row, 'multi', '\\\\multi')
                    new_first_row <- stringr::str_replace_all(new_first_row, 'textit', '\\\\textit')
                    tbl[first_row_index] <- new_first_row
                    if ( cat_output ) {
                        cat(tbl, sep='\n')
                    }
                    if ( !is.null(out_file) ) {
                        cat(tbl, sep='\n', file=out_file)
                    }
                }        
        
    custom_table(c('SHP Switzerland', 'LISS Netherlands'),
                out_file="./table-3.tex",
                shp.fit.pooling.trust_in_government,  shp.fit.pooling.control.trust_in_government, 
                shp.fit.pooling.satisfaction_with_democracy, shp.fit.pooling.control.satisfaction_with_democracy,
                shp.fit.pooling.life_satisfaction, shp.fit.pooling.control.life_satisfaction,
                
                liss.fit.pooling.trust_in_government,  liss.fit.pooling.control.trust_in_government, 
                liss.fit.pooling.satisfaction_with_democracy, liss.fit.pooling.control.satisfaction_with_democracy,
                liss.fit.pooling.life_satisfaction, liss.fit.pooling.control.life_satisfaction,
                type = "latex",
                omit.stat=c("LL","ser","f","adj.rsq"), 
                ci=FALSE, digits=2, 
                ci.level=0.95,
                single.row=FALSE, 
                label = "table-3", 
                font.size="tiny", 
                table.placement="!ht", 
                column.sep.width = "-4pt",
                title = "SHP Switzerland and LISS Netherlands: pooled models",
                align = TRUE,
                column.labels = c("(M1)", "(M2)", "(M3)", "(M4)", "(M5)", "(M6)", "(M7)", "(M8)", "(M9)", "(M10)", "(M11)", "(M12)"), 
                model.names = FALSE,
                model.numbers = FALSE,
                star.cutoffs = c(0.05, 0.01, 0.001),
                                covariate.labels = c("Unemployed", "Age", "Education", "Member"),
                dep.var.labels = dep.var.labels)         
              
        
  
       
 

                     
           
# TABLE 4: FE TABLE ####           
           stargazer(shp.fit.fe.trust_in_government,  shp.fit.fe.control.trust_in_government, 
                shp.fit.fe.satisfaction_with_democracy, shp.fit.fe.control.satisfaction_with_democracy,
                shp.fit.fe.life_satisfaction, shp.fit.fe.control.life_satisfaction,
                
                liss.fit.fe.trust_in_government,  liss.fit.fe.control.trust_in_government, 
                liss.fit.fe.satisfaction_with_democracy, liss.fit.fe.control.satisfaction_with_democracy,
                liss.fit.fe.life_satisfaction, liss.fit.fe.control.life_satisfaction,
                type = "latex",
                out="./table-4.tex",
                omit.stat=c("LL","ser","f","adj.rsq"), 
                ci=FALSE, digits=2, 
                ci.level=0.95,
                single.row=FALSE, 
                label = "table-4", 
                font.size="tiny", 
                table.placement="!ht", 
                column.sep.width = "-4pt",
                title = "SHP Switzerland and LISS Netherlands: fixed effects models",
                align = TRUE,
                column.labels = c("(M13)", "(M14)", "(M15)", "(M16)", "(M17)", "(M18)", "(M19)", "(M20)", "(M21)", "(M22)", "(M23)", "(M24)"), 
                model.names = FALSE,
                model.numbers = FALSE,
                star.cutoffs = c(0.05, 0.01, 0.001),
                                covariate.labels = c("Unemployed", "Age", "Education", "Member"),
                dep.var.labels = dep.var.labels) 
      

           


        # CUSTOM TABLE
                custom_table <- function(dataset_labels, ..., cat_output=TRUE, out_file=NULL) {
                    tbl <- capture.output(stargazer::stargazer(...))
                    pattern1 <- 'Dependent variable:'
                    pattern2 <- '(?<= \\& ).+(?= \\\\)'
                    first_row_index <- which(grepl(pattern=pattern1, x=tbl))
                    first_row <- tbl[first_row_index]
                    first_row <- gsub("\\[[0-9]+\\]", "", first_row)
                    colspan <- as.numeric(gsub(pattern='[^0-9]+', replacement='', first_row))
                    colspan <- colspan / length(dataset_labels)
                    new_first_row <- sub('[0-9]+', colspan, first_row)
                    replacement <- rep(stringr::str_extract(new_first_row, pattern2), 2)
                    replacement <- stringr::str_replace(replacement, pattern1, dataset_labels)
                    replacement <- paste(replacement, collapse=' & ')
                    new_first_row <- stringr::str_replace(new_first_row, pattern2, replacement)
                    new_first_row <- stringr::str_replace_all(new_first_row, 'multi', '\\\\multi')
                    new_first_row <- stringr::str_replace_all(new_first_row, 'textit', '\\\\textit')
                    tbl[first_row_index] <- new_first_row
                    if ( cat_output ) {
                        cat(tbl, sep='\n')
                    }
                    if ( !is.null(out_file) ) {
                        cat(tbl, sep='\n', file=out_file)
                    }
                }        
        
    custom_table(c('SHP Switzerland', 'LISS Netherlands'),
                out_file='./table-4.tex',        
                shp.fit.fe.trust_in_government,  shp.fit.fe.control.trust_in_government, 
                shp.fit.fe.satisfaction_with_democracy, shp.fit.fe.control.satisfaction_with_democracy,
                shp.fit.fe.life_satisfaction, shp.fit.fe.control.life_satisfaction,
                
                liss.fit.fe.trust_in_government,  liss.fit.fe.control.trust_in_government, 
                liss.fit.fe.satisfaction_with_democracy, liss.fit.fe.control.satisfaction_with_democracy,
                liss.fit.fe.life_satisfaction, liss.fit.fe.control.life_satisfaction,
                type = "latex",
                omit.stat=c("LL","ser","f","adj.rsq"), 
                ci=FALSE, digits=2, 
                ci.level=0.95,
                single.row=FALSE, 
                label = "table-4", 
                font.size="tiny", 
                table.placement="!ht", 
                column.sep.width = "-4pt",
                title = "SHP Switzerland and LISS Netherlands: fixed effects models",
                align = TRUE,
                column.labels = c("(M13)", "(M14)", "(M15)", "(M16)", "(M17)", "(M18)", "(M19)", "(M20)", "(M21)", "(M22)", "(M23)", "(M24)"), 
                model.names = FALSE,
                model.numbers = FALSE,
                star.cutoffs = c(0.05, 0.01, 0.001),
                                covariate.labels = c("Unemployed", "Age", "Education", "Member"),
                dep.var.labels = dep.var.labels)         
                         
           
           
           
# TABLE 5: WFE TABLE ####
  regressors <- c("Unemployed", "Age", "Education", "Member")
  d <- as.data.frame(matrix(rnorm(10 * 5), nc = 5))
  dep.var <- "Trust_in_government"
  names(d) <- c(dep.var, regressors)
  f <- as.formula(paste(dep.var, "~ 0 +", paste(regressors, collapse = "+")))
  p1 <- lm(f, d)
  dep.var <- "Satisfaction_with_democracy"
  names(d) <- c(dep.var, regressors)
  f <- as.formula(paste(dep.var, "~ 0 +", paste(regressors, collapse = "+")))
  p2 <- lm(f, d)
  dep.var <- "Life_satisfaction"
  names(d) <- c(dep.var, regressors)
  f <- as.formula(paste(dep.var, "~ 0 +", paste(regressors, collapse = "+")))
  p3 <- lm(f, d)


  stargazer(p1, p1, p2, p2, p3, p3, p1, p1, p2, p2, p3, p3,
    coef = list(as.numeric(summary(shp.fit.wfe_fe.trust_in_government)[2]$coefficients[,1]),
                as.numeric(summary(shp.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,1]),
                as.numeric(summary(shp.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,1]),
                as.numeric(summary(shp.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,1]),
                as.numeric(summary(shp.fit.wfe_fe.life_satisfaction)[2]$coefficients[,1]),
                as.numeric(summary(shp.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,1]),
                
                as.numeric(summary(liss.fit.wfe_fe.trust_in_government)[2]$coefficients[,1]),
                as.numeric(summary(liss.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,1]),
                as.numeric(summary(liss.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,1]),
                as.numeric(summary(liss.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,1]),
                as.numeric(summary(liss.fit.wfe_fe.life_satisfaction)[2]$coefficients[,1]),
                as.numeric(summary(liss.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,1])
                
                ),
    se = list(as.numeric(summary(shp.fit.wfe_fe.trust_in_government)[2]$coefficients[,2]),
                as.numeric(summary(shp.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,2]),
                as.numeric(summary(shp.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,2]),
                as.numeric(summary(shp.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,2]),
                as.numeric(summary(shp.fit.wfe_fe.life_satisfaction)[2]$coefficients[,2]),
                as.numeric(summary(shp.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,2]),
              
              as.numeric(summary(liss.fit.wfe_fe.trust_in_government)[2]$coefficients[,2]),
                as.numeric(summary(liss.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,2]),
                as.numeric(summary(liss.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,2]),
                as.numeric(summary(liss.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,2]),
                as.numeric(summary(liss.fit.wfe_fe.life_satisfaction)[2]$coefficients[,2]),
                as.numeric(summary(liss.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,2])
              ),
    t = list(as.numeric(summary(shp.fit.wfe_fe.trust_in_government)[2]$coefficients[,3]),
                as.numeric(summary(shp.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,3]),
                as.numeric(summary(shp.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,3]),
                as.numeric(summary(shp.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,3]),
                as.numeric(summary(shp.fit.wfe_fe.life_satisfaction)[2]$coefficients[,3]),
                as.numeric(summary(shp.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,3]),
             
             as.numeric(summary(liss.fit.wfe_fe.trust_in_government)[2]$coefficients[,3]),
                as.numeric(summary(liss.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,3]),
                as.numeric(summary(liss.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,3]),
                as.numeric(summary(liss.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,3]),
                as.numeric(summary(liss.fit.wfe_fe.life_satisfaction)[2]$coefficients[,3]),
                as.numeric(summary(liss.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,3])
             
             ),  
    p = list(as.numeric(summary(shp.fit.wfe_fe.trust_in_government)[2]$coefficients[,4]),
                as.numeric(summary(shp.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,4]),
                as.numeric(summary(shp.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,4]),
                as.numeric(summary(shp.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,4]),
                as.numeric(summary(shp.fit.wfe_fe.life_satisfaction)[2]$coefficients[,4]),
                as.numeric(summary(shp.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,4]),
             
             as.numeric(summary(liss.fit.wfe_fe.trust_in_government)[2]$coefficients[,4]),
                as.numeric(summary(liss.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,4]),
                as.numeric(summary(liss.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,4]),
                as.numeric(summary(liss.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,4]),
                as.numeric(summary(liss.fit.wfe_fe.life_satisfaction)[2]$coefficients[,4]),
                as.numeric(summary(liss.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,4])
             ),  
    omit.stat = "all",
    notes = "SEs in parentheses.",
    notes.append = TRUE,
    out = "table-5.tex",
    font.size = "tiny",
    label = "table-5",
    table.placement="!ht",
    column.sep.width = "-4pt", 
    title = "SHP Switzerland and LISS Netherlands: weighted fixed effects models",
    digit.separator="",
    rownames = FALSE,
    digits = 2,
    align = TRUE,
    digits.extra = 0,
    column.labels = c("(M25)", "(M26)", "(M27)", "(M28)", "(M29)", "(M30)", "(M31)", "(M32)", "(M33)", "(M34)", "(M35)", "(M36)"), 
    model.names = FALSE,
    model.numbers = FALSE,
    star.cutoffs=c(0.05,0.01,0.001))  




        # CUSTOM TABLE
                custom_table <- function(dataset_labels, ..., cat_output=TRUE, out_file=NULL) {
                    tbl <- capture.output(stargazer::stargazer(...))
                    pattern1 <- 'Dependent variable:'
                    pattern2 <- '(?<= \\& ).+(?= \\\\)'
                    first_row_index <- which(grepl(pattern=pattern1, x=tbl))
                    first_row <- tbl[first_row_index]
                    first_row <- gsub("\\[[0-9]+\\]", "", first_row)
                    colspan <- as.numeric(gsub(pattern='[^0-9]+', replacement='', first_row))
                    colspan <- colspan / length(dataset_labels)
                    new_first_row <- sub('[0-9]+', colspan, first_row)
                    replacement <- rep(stringr::str_extract(new_first_row, pattern2), 2)
                    replacement <- stringr::str_replace(replacement, pattern1, dataset_labels)
                    replacement <- paste(replacement, collapse=' & ')
                    new_first_row <- stringr::str_replace(new_first_row, pattern2, replacement)
                    new_first_row <- stringr::str_replace_all(new_first_row, 'multi', '\\\\multi')
                    new_first_row <- stringr::str_replace_all(new_first_row, 'textit', '\\\\textit')
                    tbl[first_row_index] <- new_first_row
                    if ( cat_output ) {
                        cat(tbl, sep='\n')
                    }
                    if ( !is.null(out_file) ) {
                        cat(tbl, sep='\n', file=out_file)
                    }
                }        
        
    custom_table(c('SHP Switzerland', 'LISS Netherlands'),
                out_file='./table-5.tex',        
                p1, p1, p2, p2, p3, p3, p1, p1, p2, p2, p3, p3,
                  coef = list(as.numeric(summary(shp.fit.wfe_fe.trust_in_government)[2]$coefficients[,1]),
                              as.numeric(summary(shp.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,1]),
                              as.numeric(summary(shp.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,1]),
                              as.numeric(summary(shp.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,1]),
                              as.numeric(summary(shp.fit.wfe_fe.life_satisfaction)[2]$coefficients[,1]),
                              as.numeric(summary(shp.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,1]),
                              
                              as.numeric(summary(liss.fit.wfe_fe.trust_in_government)[2]$coefficients[,1]),
                              as.numeric(summary(liss.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,1]),
                              as.numeric(summary(liss.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,1]),
                              as.numeric(summary(liss.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,1]),
                              as.numeric(summary(liss.fit.wfe_fe.life_satisfaction)[2]$coefficients[,1]),
                              as.numeric(summary(liss.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,1])
                              
                              ),
                  se = list(as.numeric(summary(shp.fit.wfe_fe.trust_in_government)[2]$coefficients[,2]),
                              as.numeric(summary(shp.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,2]),
                              as.numeric(summary(shp.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,2]),
                              as.numeric(summary(shp.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,2]),
                              as.numeric(summary(shp.fit.wfe_fe.life_satisfaction)[2]$coefficients[,2]),
                              as.numeric(summary(shp.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,2]),
                            
                            as.numeric(summary(liss.fit.wfe_fe.trust_in_government)[2]$coefficients[,2]),
                              as.numeric(summary(liss.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,2]),
                              as.numeric(summary(liss.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,2]),
                              as.numeric(summary(liss.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,2]),
                              as.numeric(summary(liss.fit.wfe_fe.life_satisfaction)[2]$coefficients[,2]),
                              as.numeric(summary(liss.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,2])
                            ),
                  t = list(as.numeric(summary(shp.fit.wfe_fe.trust_in_government)[2]$coefficients[,3]),
                              as.numeric(summary(shp.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,3]),
                              as.numeric(summary(shp.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,3]),
                              as.numeric(summary(shp.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,3]),
                              as.numeric(summary(shp.fit.wfe_fe.life_satisfaction)[2]$coefficients[,3]),
                              as.numeric(summary(shp.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,3]),
                           
                           as.numeric(summary(liss.fit.wfe_fe.trust_in_government)[2]$coefficients[,3]),
                              as.numeric(summary(liss.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,3]),
                              as.numeric(summary(liss.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,3]),
                              as.numeric(summary(liss.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,3]),
                              as.numeric(summary(liss.fit.wfe_fe.life_satisfaction)[2]$coefficients[,3]),
                              as.numeric(summary(liss.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,3])
                           
                           ),  
                  p = list(as.numeric(summary(shp.fit.wfe_fe.trust_in_government)[2]$coefficients[,4]),
                              as.numeric(summary(shp.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,4]),
                              as.numeric(summary(shp.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,4]),
                              as.numeric(summary(shp.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,4]),
                              as.numeric(summary(shp.fit.wfe_fe.life_satisfaction)[2]$coefficients[,4]),
                              as.numeric(summary(shp.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,4]),
                           
                           as.numeric(summary(liss.fit.wfe_fe.trust_in_government)[2]$coefficients[,4]),
                              as.numeric(summary(liss.fit.wfe_fe.control.trust_in_government)[2]$coefficients[,4]),
                              as.numeric(summary(liss.fit.wfe_fe.satisfaction_with_democracy)[2]$coefficients[,4]),
                              as.numeric(summary(liss.fit.wfe_fe.control.satisfaction_with_democracy)[2]$coefficients[,4]),
                              as.numeric(summary(liss.fit.wfe_fe.life_satisfaction)[2]$coefficients[,4]),
                              as.numeric(summary(liss.fit.wfe_fe.control.life_satisfaction)[2]$coefficients[,4])
                           ),  
                  omit.stat = "all",
                  notes = "Heteroscedastic / Autocorrelation Robust Standard Errors in parentheses.",
                  notes.append = TRUE,
                  font.size = "tiny",
                  label = "table-5",
                  table.placement="!ht",
                  column.sep.width = "-4pt", 
                  title = "SHP Switzerland and LISS Netherlands: weighted fixed effects models",
                  digit.separator="",
                  rownames = FALSE,
                  digits = 2,
                  align = TRUE,
                  digits.extra = 0,
                  column.labels = c("(M25)", "(M26)", "(M27)", "(M28)", "(M29)", "(M30)", "(M31)", "(M32)", "(M33)", "(M34)", "(M35)", "(M36)"), 
                  model.names = FALSE,
                  model.numbers = FALSE,
                  star.cutoffs=c(0.05,0.01,0.001),
                  covariate.labels = c("Unemployed", "Age", "Education", "Member"),
                  dep.var.labels = dep.var.labels)         
                                         






# FOOTNOTE 7 ####
  # Estimating the within individual variance across time to be better able to compare the effects of 
  # political evaluations to those of life satisfaction
    rm(list=ls())
    load(file = "./data-long-shp.RData") 
    load(file = "./data-long-liss.RData")  

  # SHP
    sd.trust_in_government.shp <- sd(data.long.shp$trust_in_government, na.rm=TRUE) # Variation across 
    sd.satisfaction_with_democracy.shp <- sd(data.long.shp$satisfaction_with_democracy, na.rm=TRUE) # Variation across 
    sd.life_satisfaction.shp <- sd(data.long.shp$life_satisfaction, na.rm=TRUE) # Variation across 
    # Variance(Individual values - mean(for each individual))
            
    x <- data.long.shp %>% group_by(unit) %>% 
    mutate(mean_trust_in_government=mean(trust_in_government, na.rm=TRUE))  %>% 
    mutate(centered_trust_in_government = trust_in_government - mean_trust_in_government) %>% 
    mutate(mean_satisfaction_with_democracy=mean(satisfaction_with_democracy, na.rm=TRUE))  %>% 
    mutate(centered_satisfaction_with_democracy = satisfaction_with_democracy - mean_satisfaction_with_democracy) %>% 
    mutate(mean_life_satisfaction=mean(life_satisfaction, na.rm=TRUE))  %>% 
    mutate(centered_life_satisfaction = life_satisfaction - mean_life_satisfaction)
      
    sd(x$centered_trust_in_government, na.rm=TRUE) # SD of deviation from individual mean across years (
    sd(x$centered_satisfaction_with_democracy, na.rm=TRUE)
    sd(x$centered_life_satisfaction, na.rm=TRUE)

    mean(x$centered_trust_in_government, na.rm=TRUE)
    mean(x$centered_satisfaction_with_democracy, na.rm=TRUE)
    mean(x$centered_life_satisfaction, na.rm=TRUE)

  
      
      
  # SHP
    sd.trust_in_government.liss <- sd(data.long.liss$trust_in_government, na.rm=TRUE) # Variation across 
    sd.satisfaction_with_democracy.liss <- sd(data.long.liss$satisfaction_with_democracy, na.rm=TRUE) # Variation across 
    sd.life_satisfaction.liss <- sd(data.long.liss$life_satisfaction, na.rm=TRUE) # Variation across 
    # Variance(Individual values - mean(for each individual))
            
    x <- data.long.liss %>% group_by(unit) %>% 
    mutate(mean_trust_in_government=mean(trust_in_government, na.rm=TRUE))  %>% 
    mutate(centered_trust_in_government = trust_in_government - mean_trust_in_government) %>% 
    mutate(mean_satisfaction_with_democracy= mean(satisfaction_with_democracy, na.rm=TRUE))  %>% 
    mutate(centered_satisfaction_with_democracy = satisfaction_with_democracy - mean_satisfaction_with_democracy) %>% 
    mutate(mean_life_satisfaction=mean(life_satisfaction, na.rm=TRUE))  %>% 
    mutate(centered_life_satisfaction =    life_satisfaction - mean_life_satisfaction)
      
    sd(x$centered_trust_in_government, na.rm=TRUE) # SD of deviation from individual mean across years
    sd(x$centered_satisfaction_with_democracy, na.rm=TRUE)
    sd(x$centered_life_satisfaction, na.rm=TRUE)
  
    mean(x$centered_trust_in_government, na.rm=TRUE)
    mean(x$centered_satisfaction_with_democracy, na.rm=TRUE)
    mean(x$centered_life_satisfaction, na.rm=TRUE)

      
      
    
  
  
  

```
    



\setlength{\tabcolsep}{2pt}

# Introduction
Trust in government and more generally satisfaction with democracy are regarded as indicators of the stability and performance of democratic systems but also as important determinants thereof [@Almond1963-bp; @Easton1975-pe; @Pharr2000-qy; @Dalton2004-ba; @Hetherington2005-el; @Levi2000-dx]. Especially in the wake of the economic crisis in 2008, scholars rang the alarm bells and pointed to the threat that rising unemployment levels may pose to democratic systems [@Arias2013-px; @Kroknes2015-ft; @Muro2014-jg; @Roth2009-jh]. While most research focuses on unemployment's negative personal consequences such as depression or suicidal tendencies, there is also a long research tradition that links it to political phenomena such as voting behavior and political extremism [e.g. @Jahoda1974-or; @Bay2002-fg; @Lundin2009-gh; @Falk2011-ni; @Siedler2006-yw; @Linn1985-gi; @Stokes1984-so]. This research program, in part, speaks to the classic debate that contrasts pocketbook voters whose preferences are assumed to be "swayed most of all by the immediate and tangible circumstances of their private lives" [@Kinder1981-nz, 130], and sociotropic voters whose preferences are influenced by a country's economic condition [@Kinder1981-nz, 129-130; @Hansford2015-pd].     
The present study is guided by the following question: *Does unemployment affect political evaluations in the form of trust in government and satisfaction with democracy?* We contribute to current scholarship in several ways. First, while the classic pocketbook vs. sociotropic voter debate focuses on voting behavior, we investigate the link between unemployment and political evaluations, i.e. trust in government and satisfaction with democracy [e.g. @Kinder1981-nz; @Hansford2015-pd]. Both are regarded as essential resources for the performance and stability of political systems [e.g. @Hetherington1998-kn; @Levi2000-dx]. We thereby contribute to a growing literature that investigates this link empirically [e.g. @Arias2013-px; @Kroknes2015-ft; @Muro2014-jg; @Roth2009-jh]. We summarize previous arguments and empirical evidence, and provide an overview of what we know so far.    
Second, empirical evidence on this relationship is limited. It is either U.S.-centered, comparative in nature, or characterized by certain shortcomings. While unemployment regularly appears as a control variable in multivariate models [@Armingeon2014-ut; @Armingeon2014-xg; @Mishler2001-fp; @Foster2017-si], few studies focus on it as a principal cause, and if so, they operate on the group level comparing either countries or cohorts [@Arias2013-px; @Roth2011-nb]. Here, we focus on the impact of direct, individual-level experiences of unemployment.^[@Laurence2015-nk uses a similar approach but focuses on its impact on generalized trust. Similarly, @Margalit2013-ph and @Naumann2016-yh investigate the impact of unemployment on social policy preferences.] Our study provides a stronger set of evidence in that it expands macro-level evidence with evidence on the individual level and focuses on causal identification. In doing so, we rely on panel data which allows us to investigate the impact of individual-level changes in employment status on individual-level changes in political evaluations. We study this relationship on the basis of data from two different European countries, Switzerland and the Netherlands. This choice is linked both to data availability -- we can rely on high-quality panel surveys that contain the necessary measures -- and to the fact that we expect less crisis-induced distortions in those countries.    
Third, we also examine the effect of unemployment on a control outcome -- life satisfaction. This additional analysis allows us to ensure that our findings are not merely a result of the design choices we made. By showing that our design identifies short-term effects of unemployment on life satisfaction, we alleviate concerns that it may be too conservative to study effects on trust in government or satisfaction with democracy.
We proceed as follows: Section [2](#sec:theory) outlines arguments and empirical evidence that link unemployment and political evaluations. Section [3](#sec:data) presents the design, data and measures. Section [4](#sec:results) summarizes the results. Section [5](#sec:conclusion) provides a summary, discusses limitations and provides rationales for future research.


# Theory, hypotheses and empirical evidence {#sec:theory}
In this study, we link short-term unemployment to political evaluations.^[While the effects of long-term unemployment are just as relevant [e.g. @European_Commission2012-pk], panel surveys generally include too few observations of long-term unemployed respondents to study them in a meaningful way.] Various studies have pointed to direct and indirect mechanisms that connect unemployment to political evaluations [@Ahn2004-mg; @Chabanet2007-ro; @Hudson2006-hz; @Newton2011-ix]. First, we may argue that there is a direct causal path. Let's assume that A loses her job. Given that A blames the government or the political system in general, we would assume that A's support for these same institutions decreases [@Hudson2006-hz, 59; @Mishler2005-mk]. Following this idea, it is argued that job "[d]isplacement may erode institutional-based trust in employers and the economic sphere in general" [@Laurence2015-nk, 47].^[@Laurence2015-nk [p. 48] suggests that the a potential effect of unemployment on generalised trust is mediated by individuals' institutional trust. See also @Delhey2003-hv, @Misztal2001-vv, @Perrucci2009-yq and @Uslaner2002-ks.] While we would expect stronger effects for evaluations of government, people may very well translate their frustration into dissatisfaction with a political system in general.   
Second, there may be various indirect causal paths: becoming unemployed leads to other events that in turn may affect someone's political evaluations. To start, unemployed individuals encounter and experience various institutions that assess their right to benefits and assist them in finding a new job. Those institutions often demand a lot of engagement on the part of the unemployed. Negative experiences with such lower-level institutions (e.g. an employment office) may spill over into one's overall evaluation of political institutions. Unemployment is also linked to various other negative outcomes, i.e. it is supposed to lead to a loss of identity and self-esteem, to a feeling of marginalization or to decrease life satisfaction, optimism, personal efficacy, political participation and to increase stress, anxiety about the future and depression [@Ahn2004-mg; @Archer1993-bq; @Chabanet2007-ro; @Leana1992-cp; @Goldsmith1996-ks; @Laurence2015-nk; @Linn1985-gi; @Rantakeisu1997-lb; @Scott1979-aw; @Waters2007-os; @Winkelmann1998-kb; @Zawadzki1935-gg, 235]. These outcomes in turn may affect political evaluations such as trust in government/satisfaction with democracy. For instance, as depression changes the outlook on life more generally, it should also affect the evaluation of political objects negatively. Overall, these various mechanisms lead to a first hypothesis: *unemployment has a negative effect on trust in government and satisfaction with democracy ($H_{1}$)*.   
At the same time, the above arguments hinge on certain assumptions, the rejection of which leads to an alternative hypothesis. In what concerns the direct effect described, it really hinges on the assumption that someone who becomes unemployed blames the political system or specific institutions for his misfortune. In other words, if someone does not draw the connection between his personal situation and the government/political system, this explanation loses validity. It is also possible that the blame is directed at other actors, e.g. economic actors.      
Second, states make various efforts to cope with the problem of unemployment and implement policies as well as special programs to simplify the reinsertion in the labor market. Fighting unemployment is one of governments' most important tasks (Cezanne 2005, 275). Someone who loses his job is not left alone, but rather helped by the state in many ways, especially in developed countries. If unemployed persons feel that the political institutions are on their side and help them, their political evaluations should either not change at all or possibly in a positive direction [@Roth2009-jh]. These arguments lead to an alternative hypothesis: *unemployment has no effect on trust in government and satisfaction with democracy ($H_{0}$).*    
While the causal pathways described above are hardly testable without the necessary fine-grained data, they provide feasible stories for both $H_{1}$ and $H_{0}$. Similarly, empirical evidence is inconsistent and supports both hypotheses. A first study analyses the General Social Survey 1972-79 with pooled cross-sectional models, introduces unemployment as one of many variables in a structural equation model and yields the following conclusion [@Brehm1997-qy, 1016]: "as aggregate unemployment and inflation fall, and economic expectations rise, confidence in federal institutions also rise". Another study investigates data from the Eurobarometer and the Latinobarometer, uses cohorts as unit of analysis and concludes that the relationship between employment and trust depends on context: increases in cyclical unemployment precede decreases in trust among Europeans, but the opposite seems true among Latin Americans [@Arias2013-px]. A third study investigates how the financial crisis of 2009 and its consequences affected political trust. Analyzing data from the Eurobarometer, the authors investigate 27 EU countries and find that declines in trust in government are related to an increase in unemployment especially in the EU-15 countries [@Roth2011-nb]. A study of the origins of political trust in Post-Communist societies relies on data from the New Democracies Barometer V and the New Russia Barometer VII. It concludes that the "recent experience of unemployment also significantly reduces political trust, but its effect are weak and add little to the overall explanation of trust" [@Mishler2001-fp, 52]. Finally, a study relying on the Eurobarometer, examines the decline of political satisfaction and trust towards parliament in 26 European countries. Unemployment is added as a control variable and has a negative effect on both satisfaction and political trust [@Armingeon2014-xg, 434]. 



# Data, measures and design {#sec:data}

We investigate three outcomes: *trust in government*, *satisfaction with democracy* and *life satisfaction*. While we lack strong evidence that causally links unemployment and the former two outcomes, there is convincing evidence that unemployment affects life satisfaction negatively [cf. @Winkelmann1998-kb]. Therefore, we use the latter as 'control outcome' to validate our design.  
The data comes from two panel surveys collected in Switzerland and the Netherlands. We restrict our sample to individuals of working age between 18 and 65 years who  can  potentially  experience a period of    unemployment. Both countries show comparably low levels of unemployment within Europe. In the first quartile of 2017, the unemployment rate (national definition) in both countries was at 5.3 percent [@Oecd2017-lj], the more comparable harmonized unemployment rate (HUR) was at 4.9 percent in Switzerland and at 6.7 percent in the Netherlands [@Oecd2017-pq]. Moreover, both countries were among those that weathered the economic crisis relatively well. While unemployment skyrocketed in countries such as Greece or Spain, the increases in Switzerland and the Netherlands were much lower in comparison [@Oecd2017-pq]. Both countries’ electoral systems can be classified as proportional; however, there are various institutional differences. Such institutional differences may, in principle, be responsible for any differences we find between the two countries. For instance, Switzerland is characterized by extensive direct democratic institutions and rights compared to the Netherlands, were the barriers to such forms of participation are higher. In other words, if we were to observe significantly different results across those two datasets, institutional factors may lay at the origin of those differences.      
First, we use data from the *Swiss Household Panel Study (SHP)*, which follows a random sample of households in Switzerland over time by means of computer-assisted telephone interviewing. The SHP started in 1999 with 5,074 households/12,931 household members. In 2004, a second sample of 2,538 households/6,569 household members was added. Second, we rely on the *Longitudinal Internet Studies for the Social Sciences (LISS)*, which is the only other panel study to our knowledge that contains the measures we require. The LISS is based on a random sample of Dutch households drawn from the population register. It consists of 5000 households comprising 8000 household members. Monthly data have been collected by online questionnaires of about 15 to 30 minutes since October 2007. One member in the household provides the household data and updates this information at regular intervals. As described above, both Switzerland and the Netherlands are characterized by rather low rates of unemployment. Table \ref{table-1} gives an overview of the distribution of unemployment in our samples across time.     

\input{./table-1.tex}

\input{./table-2.tex}



The measures for both outcomes and treatment are similar across the SHP and the LISS. Table \ref{table-2} gives an overview of the panel waves that contain our measures.     
In the *SHP*, our outcomes are measured as follows: Beginning with the first wave in 1999 (with the exception of 2010), respondents were asked both a trust question and a satisfaction-with-democracy question: "*How much confidence do you have in [The Federal Government (in Bern)], if 0 means 'no confidence' and 10 means 'full confidence'?*" and "*Overall, how satisfied are you with the way in which democracy works in our country, if 0 means 'not at all satisfied' and 10 'completely satisfied'?*" In addition, life satisfaction was queried starting in 2000: "*In general, how satisfied are you with your life if 0 means 'not at all satisfied' and 10 means 'completely satisfied'?*". Our treatment variable ```Unemployed``` takes the value ```1``` if a respondent's working status is actively occupied and is ```0``` if a respondent's working status is unemployed. Respondents who are not in the labor force are coded as missing. Most of the models we estimate focus on change in employment status, i.e. the treatment group are respondents that have become unemployed, whereas the control group is made up of people that have remained employed.^[As unemployment is measured in yearly intervals, a situation in which respondents become unemployed and get another job within this period can not be observed. Nevertheless, we assume that the number of such cases is relatively low. In addition, all those coded as unemployed also answered "*yes*" to the question "*In the last four weeks, have you been looking for a job?*". In other words, they indicated that they are actively seeking a job.]       
In the *LISS*, our outcomes are measured as follows: beginning with the first wave in October 2007 respondents were asked to respond to questions about trust in government, satisfaction with democracy and life satisfaction. Trust in government is measured with the question "*Can you indicate, on a scale from 0 to 10, how much confidence you personally have in each of the following institutions [Dutch government]? 0 means that you have no confidence in an institution and 10 means that you have full confidence*". Satisfaction with democracy is measured with the question "*How satisfied are you with the way in which the following institutions operate in the Netherlands? 0 means that you are very dissatisfied with how the institution operates and 10 means that you are very satisfied*" and respondents evaluate the institution "*democracy*". Life satisfaction is measured with the question "*How satisfied are you with the life you lead at the moment? 0 means not at all satisfied with the life you lead at the moment and 10 means you are completely satisfied*". Apart from that, respondents are queried about their employment situation. Our treatment variable  ```Unemployed``` takes the value ```1``` if a respondent indicates "*I perform paid work (even if is it just for one or several hours per week or for a brief period)*" and it is ```0``` if a respondent indicates "*I am looking for work following the loss of my previous job*". While the LISS measures are not exactly the same as in the Swiss Household Panel, they represent satisfactory proxies. Table \ref{table-2} in the appendix presents summary statistics for all variables used in the analysis.    
In terms of design, a major concern in investigating the link between unemployment and our outcomes are time-invariant and time-variant confounders that may affect both phenomena. Observing units at multiple points in time allows us to link the variance of within-unit changes in unemployment to the variance of within-unit changes in our outcomes of interest.             
We rely on models classically used to analyze panel data [@Croissant2008-tb] but proceed with newer estimation techniques [@Imai2016-td].^[Analyses were conducted relying on R [@R_Core_Team2017-bp], the plm R package [@Croissant2017-mt] and the wfe R package [@Kim2017-vu]. Tables were generated using the Stargazer R package [@Hlavac2014-wd].] First, we estimate linear models that pool the data across all units $i$ and time periods $t$ [@Croissant2008-tb, 2]. The estimated treatment effects represent the difference between observations of individuals who became unemployed and observations of individuals who did not. Thus, treatment and control group may comprise observations of the same individual at different points in time. We estimate those models with and without controls (see Table \ref{table-3}). The results from this first step serve as a point of reference. Second, we continue with fixed effects models (FE models). Through demeaning the data, time-invariant individual components are removed [@Wooldridge2010-jb, 300ff; @Croissant2008-tb, 3]. Again, we estimate models with and without controls for all three outcomes (see Table \ref{table-4}).
Third, we contrast the results from the classic FE estimation strategy with newer methods developed in @Imai2016-td, namely weighted linear fixed effects regression models (WFE models). We refer the reader to @Imai2016-td for an elaborate discussion of the assumptions that are necessary to interpret estimates from fixed effects models as causal effects. @Kim2017-vu provide the software to estimate WFE models for causal inference relying on different weighting schemes (see Table \ref{table-5}).     
In what concerns causality, our main concern is selection on time-invariant covariates, i.e. stable variables that may affect both an individual's propensity to become unemployed and her political evaluations. However, time-invariant confounders cancel out of the equation in the FE and WFE models. Then there may be attributes/variables that are time-variant and affect both unemployment and trust in government/satisfaction with democracy. However, such events/changes only represent a problem, i.e. introduce bias if they are linked to both treatment and outcome and occur among a large enough number of units in our sample. While it is difficult to come up with realistic examples of that kind, we do account for a set of variables that tend to be linked to the risk of unemployment and to trust in government/satisfaction with democracy namely age, education and organizational membership [@Blackaby1999-qd; @Blundell1987-qz; @Collier2005-ja, 144; @Granovetter1973-vq, 1360; @Mishler2001-fp, 49; @Newton2011-ix; @Putnam2000-ea]. While the phenomena we control for are largely stable, they still do change at particular times of an individual's life. And changes in education, or particular jumps on the age scale, could be related to our treatment and outcomes. Moreover, they may also function as proxies for other non-stable phenomena, i.e. events that affect both unemployment and political evaluations may be more likely among those with low education. Table \ref{table-6}, \ref{table-7} and \ref{table-8} in the appendix present summary statistics for all variables used in the analysis.^[In principle, any conclusions we derive may be threatened by non-response bias, i.e. the treated/non-treated in our sample may be not representative of the corresponding groups in the population, selective attrition bias, i.e. individuals who drop out at t are systematically different in terms of treatment and outcome, and finally measurement error, e.g. individuals who become unemployed do not reveal their status to the interviewer. We have to assume that these biases are either absent or at least not strong enough to distort our findings.] 
Apart from the effect on political evaluations, we investigate the effect of unemployment on life satisfaction. This is to safeguard that our findings are not merely a result of the design choices we made.         
Finally, a comment on reverse causality. We rely on data that measures both outcome and treatment at the beginning/end of yearly periods. We relate within-year changes in the treatment to within-year changes in the outcome. In principle, we do not know when those changes occur within these time periods. In other words, we do not know when exactly people changed their employment status or their political evaluations (and what precedes what). This is a general limitation of panel data. However, in our view it is unlikely that changes in trust in government/satisfaction with democracy cause people to become unemployed. In other words, arguments that describe a causal path from trust in government/satisfaction with democracy to unemployment seem implausible, meaning that such causal paths do not realistically apply to a significant number of people in our sample.
















# Empirical results {#sec:results}

Table \ref{table-3} displays the results for the pooled data for both the SHP Switzerland and the LISS Netherlands, pooling all units (individuals) across time. The large N in the respective models reflects the number of unit*time observations. The coefficients for unemployed describe the differences in the outcome averages between those who are employed and those who are not. The respective models (M1-M12) consistently show that unemployment negatively affects trust in government, satisfaction with democracy and life satisfaction. All coefficients are statistically significant both with and without controls. Moreover, while we would argue that all coefficients are also substantively significant (outcomes are measured on 11-point scales), i.e. in terms of size, unemployment has a much larger effect on life satisfaction than on political evaluations, as can be seen from Model 5, 6, 11, 12 in Table \ref{table-3}. Table \ref{table-3} also reveals that the effects are relatively consistent across the two panel datasets. All are negative, and the differences across the two datasets are altogether not that strong. However, we would expect that the results in Table \ref{table-3} are biased, as there are various unobserved time-invariant and time-variant confounders affecting both unemployment and our outcomes of interest. 



\input{./table-3.tex}





Therefore, in a second step we rely on fixed effects models (FE) as displayed in Table \ref{table-4}. We find that the differences to the pooled models are considerable. The effect on life satisfaction is consistently statistically significant and substantially significant (M17, M18, M23, M24). In contrast, the effect on satisfaction with democracy is not statistically significant and substantially small (M15, M16, M21, M22). The effects on trust in government are substantially small and not statistically significant in the SHP (M13, M14). In the LISS dataset, the effect is stronger in the model which excludes controls (M19); however, it weakens as we add controls (M20). While these results are not exactly clear-cut, in our view, they are not consistent enough to infer that there is a causal effect of unemployment on satisfaction with democracy or trust in government in the present sample, especially for the latter outcome. First, the effects on our outcomes are much smaller compared to the effect on life satisfaction, especially when we focus on the models that include covariates (M14, M16, M20, M22). Second, only a single coefficient (M20) reaches statistical significance considering a p < 0.05 threshold. However, such a p-value is regarded by some as only providing suggestive evidence [@Benjamin2017-rf], while others suggest to abandon such arbitrary cut-off values altogether [@McShane2017-bc].

\input{./table-4.tex}




\input{./table-5.tex}





Finally, following the arguments provided in @Imai2016-td, we estimate a further set of weighted linear fixed effects (WFE) models. Table \ref{table-5} displays the corresponding results, which mirror those obtained through FE estimation. The effect on life satisfaction remains robust, with and without controls. Moreover, the effect sizes seem substantively significant. In comparison, the effects on trust in government and satisfaction (M26, M28, M32, M34) are only partly statistically significant (p < 0.05 in M28, M32). Furthermore, they are generally small in size as compared to the effect on life satisfaction, despite the fact that all outcomes are measured on 11-point scales.^[The within-unit over time variation of life satisfaction is lower than that of trust in government and satisfaction with democracy. Besides, scholars recently suggested that p-values between 0.005 and 0.05 can only be regarded as suggestive evidence [@Benjamin2017-rf, 3].] Given this inconsistency, our results seem to support $H_{0}$, namely that *unemployment has no effect on trust in government or satisfaction with democracy*. This general pattern is visualized in Figure \ref{fig-results}, which summarizes the results. We discuss limitations that may undermine this conclusion below. 


\begin{figure}[h]
\centering
\caption{Visualization of effects across models, outcomes and datasets}\label{fig-results}
		\includegraphics[width=1\linewidth]{fig-1.jpg}
\begin{flushleft}
\scriptsize Note: Filled (SHP data) and empty (LISS data) symbols represent point estimates of effects for 36 models; lines represent 95\% confidence intervals;  model names M1-M36 correspond to model names in Table 3, 4 and 5; see plot legend for further explanation; FE = fixed effects, WFE = Weighted linear fixed effects; data: Swiss Household Panel (SHP) and Longitudinal Internet Studies for the Social sciences (LISS).
\end{flushleft}
\end{figure}





# Discussion and conclusion {#sec:conclusion}
We investigate whether unemployment affects trust in government and satisfaction with democracy. We thereby contribute to current scholarship on the effects of unemployment [@Brand2015-rr; @Naumann2016-yh; @Margalit2013-ph], on causes of political trust and satisfaction with democracy [e.g. @Listhaug2017-et], and on the more general link between experiences and trust [@Listhaug2017-et; @Dinesen2015-fr]. Relying on panel data and corresponding models, we find no consistent evidence that unemployment negatively affects trust in government or satisfaction with democracy, which is in line with $H_{0}$. However, we can replicate earlier findings on the negative relationship between unemployment and life satisfaction [cf. @Winkelmann1998-kb], which suggests that our apparent non-finding is not merely a result of the methods we apply. Our findings somewhat contrast macro-level evidence that links unemployment to political trust [e.g. @Kroknes2015-ft; @Roth2011-nb] but also micro-level evidence that links unemployment to support for the welfare state and unemployment benefits [@Naumann2016-yh; @Margalit2013-ph]. The former contrast can possibly be explained by both the classic pocketbook--sociotropic voter argument and by case selection. The latter difference is more intriguing. It seems to indicate that an experience of unemployment may affect concrete attitudes towards policies linked to unemployment, while more abstract attitudes remain largely unaffected.      
Our study is characterized by limitations. These may explain the above-mentioned differences but also serve as starting points for future research. First, in line with other panel-data studies that focus on single countries [e.g. @Margalit2013-ph; @Naumann2016-yh], we analyze panel data from "only" two countries, Switzerland and the Netherlands. As discussed before, the relationship between unemployment and political evaluations may hinge on the prevalence of certain norms, on the basis of which the unemployed blame the government or the political system for their fate or not. Such a mechanism seems highly unlikely in some contexts, e.g. the U.S., but more likely in other contexts, e.g. Spain. While the effects we find are relatively consistent across two countries, more panel data from a wider set of countries may allow researchers to investigate such potential for context dependence.     
A second drawback concerns the particular types of unemployment experiences we study. We do not have enough information to properly unpack what experiences lurk behind our unemployment variable. The reasons why someone has become unemployed should matter. Future studies would ideally measure and differentiate between such reasons for unemployment in a more fine-grained way. For instance, someone whose unemployment was a direct consequence of the crisis may be quicker to connect her situation to politics. Furthermore, we focus on the effects of direct unemployment experiences. However, following the sociotropic argument, indirect experiences of unemployment, e.g. observing people in one's network [@Newman2017-ls] or in one's neighborhood [@Bisgaard2015-xb; @Oesch2013-za], may equally matter. Studying and contrasting such indirect experiences with direct experiences is an important area of future research.    
Third, time matters. To start, the length of treatment could matter. It seems plausible that long-term unemployment affects political evaluations to a greater extent than short-term unemployment. Our data do not contain enough observations of the long-term unemployed. Although collecting such data is challenging, we nevertheless think that studying the political attitudes of citizens who have been excluded from the labor market for long periods is relevant, especially given predictions of how automation may increase levels of unemployment [e.g. @Arntz2016-od]. Of course, studying such long-term lags and the effects of long-term unemployment is challenging from a design perspective. The longer an individual's period of unemployment is, the less likely we are to find a suitable control unit or observation that displays a similar life trajectory and differentiates itself only through being employed. On another note, with one-year panel periods we may fail to capture effects that are more short-term. Thus, future studies would ideally measure our individual-level outcomes on a more frequent basis both before and after the onset of unemployment.     
Finally, our investigation is limited by the sample size. In principle, it is possible that the effect of unemployment is heterogeneous across (subgroups of) individuals (treatment effect heterogeneity). For certain individuals, the causal story we provide may seem more plausible. For instance, unemployment may have a stronger effect on groups that are already disadvantaged in the labor market, such as women or individuals with lower class background. Similarly, individuals' ideology should determine whether they link their personal economic situation to a government or to the wider political system. Future data collections that comprise more individuals may allow for an exploration of such assumed treatment heterogeneity.





\newpage

# Appendix {#sec:appendix}


\input{./table-6.tex}





\input{./table-7.tex}





\input{./table-8.tex}


\normalsize


\clearpage


# References




